题意:
输入一个正整数N(题干没指出范围,默认1e5可以AC),接下来输入N行数据,每行包括一名学生的姓名,性别,学号和分数。输出三行,分别为最高分女性学生的姓名和学号,最低分男性学生的姓名和学号,前者减去后者的分数差。
AAAAAccepted code:
1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 pair<int,int>female[100007],male[100007]; 5 string name[100007],num[100007]; 6 int point[100007]; 7 char gender; 8 int cntf,cntm; 9 int main(){ 10 int n; 11 cin>>n; 12 for(int i=1;i<=n;++i){ 13 cin>>name[i]; 14 cin>>gender; 15 cin>>num[i]; 16 cin>>point[i]; 17 if(gender=='F') 18 female[++cntf]={point[i],i}; 19 else if(gender=='M') 20 male[++cntm]={point[i],i}; 21 } 22 sort(female+1,female+1+cntf); 23 sort(male+1,male+1+cntm); 24 if(!cntf) 25 cout<<"Absent"<<" "; 26 else 27 cout<<name[female[cntf].second]<<" "<<num[female[cntf].second]<<" "; 28 if(!cntm) 29 cout<<"Absent"<<" "; 30 else 31 cout<<name[male[1].second]<<" "<<num[male[1].second]<<" "; 32 if(!cntf||!cntm) 33 cout<<"NA"; 34 else 35 cout<<point[female[cntf].second]-point[male[1].second]; 36 return 0; 37 }