AcWing 1520. 男孩 vs 女孩
原题链接
简单
作者:
Value
,
2020-05-22 11:46:07
,
所有人可见
,
阅读 453
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node{
string name, sex, id;
int score;
};
vector<node> gril, boy;
bool cmp(node a, node b){
return a.score > b.score;
}
int main(){
int n;
cin >> n;
node student;
for(int i = 0; i < n; i ++ ){
cin >> student.name >> student.sex >> student.id >>student.score;
if(student.sex == "M") boy.push_back(student);
else gril.push_back(student);
}
int boyNum = boy.size();
int grilNum = gril.size();
if(grilNum == 0) cout << "Absent" << endl;
else{
sort(gril.begin(), gril.end(), cmp);
cout << gril[0].name << " " << gril[0].id << endl;
}
if(boyNum == 0) cout << "Absent" << endl;
else{
sort(boy.begin(), boy.end(), cmp);
cout << boy[boyNum - 1].name << " " << boy[boyNum - 1].id << endl;
}
if(boyNum == 0 || grilNum == 0) cout << "NA" << endl;
else cout << gril[0].score - boy[boyNum - 1].score << endl;
return 0;
}