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 N lines of student information. Each line contains a student's
name
,gender
,ID
andgrade
, separated by a space, wherename
andID
are strings of no more than 10 characters with no space,gender
is eitherF
(female) orM
(male), andgrade
is an integer between 0 and 100. It is guaranteed that all the grades are distinct.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 that of the male 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 outputNA
in the third line instead.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<bits/stdc++.h>
using namespace std;
struct node {
char name[15],id[15];
int sco;
} p,p1[1000005],p2[1000005];
bool cmp(node a,node b) {
return a.sco<b.sco;
}
int main() {
int n,sco,cnt1=0,cnt2=0;
char sex[2];
scanf("%d",&n);
for(int i=0; i<n; i++) {
scanf("%s%s%s%d",p.name,sex,p.id,&p.sco);
if(strcmp(sex,"M")==0) p1[cnt1++]=p;
else p2[cnt2++]=p;
}
sort(p1,p1+cnt1,cmp);
sort(p2,p2+cnt2,cmp);
if(cnt2==0) cout<<"Absent\n";
else cout<<p2[cnt2-1].name<<' '<<p2[cnt2-1].id<<endl;
if(cnt1==0) cout<<"Absent\n";
else cout<<p1[0].name<<' '<<p1[0].id<<endl;
if(!cnt1||!cnt2) cout<<"NA\n";
else cout<<p2[cnt2-1].sco-p1[0].sco<<endl;
return 0;
}