pat1036. Boys vs Girls (25)

Source: Internet
Author: User

1036. Boys vs Girls (25) time limit MS Memory limit 65536 KB code length limit 16000 B procedure StandardAuthor Chen, Yue

This is asked to tell the difference between the lowest grade of all the male students and the highest grade of All the female students.

Input Specification:

Each input file contains the one test case. Each case contains a positive an integer n, followed by N lines of student information. Each line contains a student's name, gender, ID and grade, separated by a space, where name and ID is strings of no more than characters with no space, gender is either F (female) or M (male), and grade are an integer between 0 and 100. It is guaranteed, the grades is distinct.

Output Specification:

For each test case, the output in 3 lines. The first line gives the name and ID of the the female student with the highest grade, and the second line gives that of the M Ale student with the lowest grade. The third line gives the difference Gradef-gradem. If One such kind of student is missing, output ' Absent ' in the corresponding line, and output ' NA ' in the third line Inste Ad.

Sample Input 1:

3Joe m Math990112 89Mike m CS991301 100Mary F EE990830 95
Sample Output 1:
Mary Ee990830joe Math9901126
Sample Input 2:
1Jean M AA980920 60
Sample Output 2:
Absentjean Aa980920na

Submit Code

1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cstring>5#include <queue>6#include <vector>7#include <cmath>8 using namespacestd; 9 structnode{Ten     Charname[ the],id[ the]; One     intgrade; A     BOOLm; - node () { -m=false; the     } - }; - BOOLCMP (node A,node b) { -     returnA.grade>B.grade; + } - intMain () { +     //freopen ("D:\\input.txt", "R", stdin); A     intN; atscanf"%d",&n); -Node *stu=NewNode[n]; -     inti,g=-1, b=-1; -     CharT; -      for(i=0; i<n;i++){ -scanf"%s", stu[i].name); inCin>>T; -         if(t=='M'){ tostu[i].m=true; +         } -scanf"%s%d",stu[i].id,&stu[i].grade); the     } *Sort (stu,stu+n,cmp); $      for(i=0; i<n;i++){Panax Notoginseng         if(!stu[i].m) { -g=i; the              Break; +         } A     } the      for(i=n-1; i>=0; i--){ +         if(STU[I].M) { -b=i; $              Break; $         } -     } -     if(g!=-1){ theprintf"%s%s\n", stu[g].name,stu[g].id); -     }Wuyi     Else{ theprintf"absent\n"); -     } Wu     if(b!=-1){ -printf"%s%s\n", stu[b].name,stu[b].id); About     } $     Else{ -printf"absent\n"); -     } -     if(g!=-1&&b!=-1){ Aprintf"%d\n", stu[g].grade-stu[b].grade); +     } the     Else{ -printf"na\n"); $     } the     return 0; the}

pat1036. Boys vs Girls (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.