1036. Boys vs Girls (25)

Source: Internet
Author: User

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:

3

Joe M Math990112 89

Mike M CS991301 100

Mary F EE990830 95

Sample Output 1:

Mary EE990830

Joe Math990112

6

Sample Input 2:

1

Jean M AA980920 60

Sample Output 2:

Absent

Jean AA980920

NA

#include <iostream> #include <string>using namespace std;struct student {char gender;    int grade;    String ID; string name;};    int main () {int n, I;    BOOL Flag_m, Flag_f;    struct student student[101];        while (cin>>n) {flag_m = Flag_f = false;        int max_grade = 0;        int min_grade = 100;        int max_f = 0, min_m; for (i=0; i<n; i++) {cin>>student[i].name>>student[i].gender>>student[i].id>>student            [I].grade;                if (Student[i].gender = = ' M ') {flag_m = true;                    if (Student[i].grade <= min_grade) {min_grade = Student[i].grade;                Min_m = i;                }} else {flag_f = true;                    if (Student[i].grade >= max_grade) {max_grade = Student[i].grade;                Max_f = i; }}} if (Flag_f) {Cout<<student[max_f].name<< "" <<student[max_f].id<<endl;                } else {cout<< "Absent" <<endl;        } if (flag_m) {cout<<student[min_m].name<< "" <<student[min_m].id<<endl;                } else {cout<< "Absent" <<endl;        } if (flag_f&&flag_m) {cout<<student[max_f].grade-student[min_m].grade<<endl;        } else {cout<< "NA" <<endl;  }} return 0;}


1036. 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.