Day55: [PAT甲级] 1036 Boys vs Girls (25分)
题源:
来自PAT真题库:
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016
代码:
dirty code凑合看吧
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<algorithm>
using namespace std;
int N;
typedef struct stu {
string name;
string gender;
string id;
int grade;
}stu;
int main() {
cin >> N;
stu low = {"null","null","null",101};
stu high= { "null","null","null",-1 };
stu X;
for (int i = 0; i < N; i++) {
cin >> X.name >> X.gender >> X.id >> X.grade;
if (X.gender == "M") {
if (low.grade > X.grade) low = X;
}
else {
if (high.grade < X.grade) high = X;
}
}
bool flag=false;
if (high.grade == -1) {
flag = true;
cout << "Absent" << endl;
}
else {
cout << high.name << " " << high.id << endl;
}
if (low.grade == 101) {
flag = true;
cout << "Absent" << endl;
}
else {
cout << low.name << " " << low.id << endl;
}
if (flag == true) cout << "NA";
else cout << high.grade - low.grade;
system("pause");
}