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,输入成绩,男生计数,女生计数,男最低分,女最高分 char nam[15],gend,id[15]; //输入信息 char name_m[15],id_m[15],name_f[15],id_f[15];//保存最低分男的个人信息,最高分女的个人信息 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 "); } else{ printf("%s %s ",name_f,id_f); } if(boyc == 0){ printf("Absent "); } else{ printf("%s %s ",name_m,id_m); } if(girlc == 0||boyc == 0){ printf("NA"); } else{ printf("%d",girlmax-boymin); } return 0; }