题目链接:点击打开链接
知识点笔记:
AC代码:
#include <iostream>
#include <algorithm>
using namespace std;
struct student{
char name[15];
char gender;
char id[15];
int grade;
}low,high,temp;
int main() {
int n;
scanf("%d",&n);
low.grade=101;
high.grade=-1;
for(int i=0;i<n;i++){
scanf("%s %c %s %d",temp.name,&temp.gender,temp.id,&temp.grade);
if(temp.gender=='M' && temp.grade<low.grade){
low=temp; //男生最低分
}else if(temp.gender=='F' && temp.grade>high.grade){
high=temp; //女生最低分
}
}
if(high.grade==-1) printf("Absent\n");
else printf("%s %s\n",high.name,high.id);
if(low.grade==101) printf("Absent\n");
else printf("%s %s\n",low.name,low.id);
if(low.grade!=101 && high.grade!=-1) printf("%d",abs(high.grade-low.grade));
else printf("NA\n");
return 0;
}