返回目录![在这里插入图片描述](https://img-blog.csdnimg.cn/20200329112258647.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ExOTIwOTkzMTY1,size_16,color_FFFFFF,t_70)
题意
给出n个学生的信息,分别找出女生分数最高者和男生分数最低者,并计算分数的差,若无男生或女生,则在对应位置输出Absent,分数差输出NA
注意点
- 使用结构体只需存储部分数据即可
- abs()函数是常用的取绝对值函数,可以记下来
#include <bits/stdc++.h>
using namespace std;
struct per{
char name[15],id[15];
int score;
}M,F,tmp;
int main(){
M.score=101;
F.score=-1;
int n;
scanf("%d",&n);
while(n--){
char a;
scanf("%s %c %s %d",tmp.name,&a,tmp.id,&tmp.score);
if(a=='M'){
if(tmp.score<M.score)M=tmp;
}else{
if(tmp.score>F.score)F=tmp;
}
}
if(F.score==-1)printf("Absent\n");
else printf("%s %s\n",F.name,F.id);
if(M.score==101)printf("Absent\n");
else printf("%s %s\n",M.name,M.id);
if(F.score==-1||M.score==101)printf("NA\n");
else printf("%d\n",abs(F.score-M.score));
return 0;
}