PATA 1036. Boys vs Girls (25), pata1036
Https://www.patest.cn/contests/pat-a-practise/1036
#include <bits / stdc ++. h>
using namespace std;
int main ()
{
int n, i, gra, boyc = 0, girlc = 0, boymin = 101, girlmax = -1; // n, input grade, boy count, girl count, lowest male score, highest female score
char nam [15], gend, id [15]; // input information
char name_m [15], id_m [15], name_f [15], id_f [15]; // Save the personal information of the lowest male, and the personal information of the highest female
scanf ("% d", & n);
for (i = 0; i <n; i ++)
{
scanf ("% s% c% s% d", nam, & gend, id, & gra);
if (gend == 'M') {
boyc ++;
if (gra <boymin) {
boymin = gra;
strcpy (name_m, nam);
strcpy (id_m, id);
}
}
else {
girlc ++;
if (gra> girlmax) {
girlmax = gra;
strcpy (name_f, nam);
strcpy (id_f, id);
}
}
}
if (girlc == 0) {
printf ("Absent \ n");
}
else {
printf ("% s% s \ n", name_f, id_f);
}
if (boyc == 0) {
printf ("Absent \ n");
}
else {
printf ("% s% s \ n", name_m, id_m);
}
if (girlc == 0 || boyc == 0) {
printf ("NA");
}
else {
printf ("% d", girlmax-boymin);
}
return 0;
}