##### 5、最高分&最低分✔
个人觉得我自己这里处理的不错
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int n;
cin>>n;
string fname,fid;int fscore=-1;
string mname,mid;int mscore=101;
for(int i=0;i<n;i++){
string name,id;
char gender;int score;
cin>>name>>gender>>id>>score;
if(gender=='F'){
if(score > fscore){
fscore = score;
fname = name;
fid = id;
}
}
else{
if(score < mscore){
mscore = score;
mname = name;
mid = id;
}
}
}
if(fscore==-1) cout<<"Absent"<<endl;
else cout<<fname<<" "<<fid<<endl;
if(mscore==101) cout<<"Absent"<<endl;
else cout<<mname<<" "<<mid<<endl;
if(fscore==-1 || mscore==101) cout<<"NA"<<endl;
else cout<<fscore-mscore<<endl;
return 0;
}
该C++代码读取学生数据,包括姓名、性别、ID和分数。它分别记录女性学生的最高分和男性学生的最低分。如果没有任何女性或男性的记录,程序会输出Absent。最后,程序会打印最高分和最低分的差值。

被折叠的 条评论
为什么被折叠?



