Home > database >  1036 Boys vs. Girls (25 points)
1036 Boys vs. Girls (25 points)

Time:10-05


This time you are 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 one test case. Each case contains a positive integer N, followed by Nlines of student information. Each line contains a student 's name, gender, ID and grade, separated by a space, where the name and ID are strings of no more than 10 characters with no space, gender is either F (female) or M (male), and grade is an integer between 0 and 100. It is guaranteed that all the grades are distinct.

The Output Specification:

For each test case, output in 3 lines. The first line gives The name and ID of The female student with The highest grade, and The second line gives The that of The male student have The lowest grade. The third line gives The difference grade? F??? Grade? M?? . If one to kind of student is missing, the output Absent in the corresponding line, and the output NA in the third line home.

The Sample Input 1:

Joe 3 M Math990112 89 Mike M CS991301 100 Mary F EE990830 95

The Sample Output 1:

Mary EE990830 Joe Math990112 6

The Sample Input 2:

1, 60 M AA980920

The Sample Output 2:

Absent Jean AA980920 NA

General idea:
Student, define structure array contains variables of the students' name, gender, ID and scores, define a structure variable tempstu, input n according to the requirement of the students' information, added to the student stu variable-length array type, will be ordered n students (girl in the former, the boy in the back, scoring from high to low), if stu [0] of sex for male, shows no girls, if stu [n - 1) gender as female, shows no boys, according to the requirements of the output output,

Code:
1036 Boys and Girls/* */
#include
#include
#include
using namespace std;
Struct student {
Char name [11].
Char gender;
Char id [11];
Int score;
} tempstu;
Bool CMP (student a, student b) {
The return of al-qeada ender!=b.g ender? Atul gawande ender B.s core;
{} int main ()
Int n;
The scanf (" % d ", & amp; N);
Vector Stu.
for(int i=0; iThe scanf (" % s % c % s % d ", & amp; Tempstu. Name, & amp; Tempstu. Gender, & amp; Tempstu. Id & amp; Tempstu. Score);
Stu. Push_back (tempstu);
}
Sort (stu. The begin (), stu. The end (), CMP);
If (stu [0]. Gender=='M')
Printf (" Absent \ nNA \ n \ n % s % s ", stu [n - 1). The name, stu [n - 1]. Id);
Else if (stu [n - 1]. Gender=='F')
Printf (" % s % s \ nAbsent \ nNA \ n ", stu [0]. Name, stu. [0] id);
The else
Printf (" % s % s \ n \ n % d % s % s ", stu [0]. Name, stu [0]. Id, stu [n - 1). The name, stu [n - 1]. Id, stu. [0] score - stu [n - 1]. Score).
return 0;
}

  • Related