1036 Boys vs Girls
Statement
Metadata
- 作者: CHEN, Yue
- 单位: 浙江大学
- 代码长度限制: 16 KB
- 时间限制: 400 ms
- 内存限制: 64 MB
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 name
, gender
, ID
and grade
, separated by a space, where name
and ID
are strings of no more than 10 characters with no space, gender
is either F
(female) or M
(male), and grade
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 Absent
in the corresponding line, and output NA
in the third line instead.
Sample Input 1
Sample Output 1
Sample Input 2
Sample Output 2
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, num, max = INT_MIN, min = INT_MAX;
string s1, s2, male_name = "", male_ID = "", female_name = "", female_ID = "";
char c;
cin >> n;
for (i = 0; i < n; i++) {
cin >> s1;
scanf(" %c", &c);
cin >> s2 >> num;
if (c == 'M') {
if (num < min) {
male_name = s1;
male_ID = s2;
min = num;
}
} else {
if (num > max) {
max = num;
female_name = s1;
female_ID = s2;
}
}
}
int flag = 1;
if (female_name != "")
cout << female_name << " " << female_ID << endl;
else
cout << "Absent\n", flag = 0;
if (male_name != "")
cout << male_name << " " << male_ID << endl;
else
cout << "Absent\n", flag = 0;
if (flag)
cout << max - min << endl;
else
cout << "NA\n";
}