题目描述
模拟一下 取个最大值即可
C++ 代码
#include <iostream>
using namespace std;
struct S
{
string name, id;
char sex;
int score;
}s[110];
int n;
int main()
{
cin >> n;
for (int i = 0; i < n; i ++) cin >> s[i].name >> s[i].sex >> s[i].id >> s[i].score;
int max_score = -1, min_score = 2e9;
string max_name, min_name, max_id, min_id;
for (int i = 0; i < n; i ++)
if (s[i].sex == 'F' && s[i].score > max_score)
{
max_score = s[i].score;
max_name = s[i].name;
max_id = s[i].id;
}
else if (s[i].sex == 'M' && s[i].score < min_score)
{
min_score = s[i].score;
min_name = s[i].name;
min_id = s[i].id;
}
if (max_score == -1 || min_score == 2e9)
{
if (max_score != -1) cout << max_name << " " << max_id << endl;
else puts("Absent");
if (min_score != 2e9) cout << min_name << " " << min_id << endl;
else puts("Absent");
puts("NA");
}
else
cout << max_name << " " << max_id << endl << min_name << " " << min_id << endl << abs(max_score - min_score);
}