AcWing 1520. 男孩 vs 女孩
原题链接
简单
作者:
xxxxuu
,
2021-04-16 17:53:24
,
所有人可见
,
阅读 2
#include <iostream>
using namespace std;
int main(){
int n;
string girl_name,girl_id,boy_name,boy_id;//女生中最高成绩的姓名和id 男生中最低成绩的姓名和id
int max_girl_socre=-1,min_boy_score=101;//女生最高成绩,男生最低成绩
cin>>n;
for(int i=0;i<n;i++){
string name,sex,id;
int score;
cin>>name>>sex>>id>>score;
if(sex=="F"){//如果是女生
if(score>max_girl_socre){
max_girl_socre=score;
girl_name=name;
girl_id=id;
}
}
if(sex=="M"){//如果是男生
if(score<min_boy_score){
min_boy_score=score;
boy_name=name;
boy_id=id;
}
}
}
//按题目格式输出
if(girl_name==""){
cout<<"Absent"<<endl;
}
else{
cout<<girl_name<<" "<<girl_id<<endl;
}
if(boy_name==""){
cout<<"Absent"<<endl;
}
else{
cout<<boy_name<<" "<<boy_id<<endl;
}
if(boy_name!="" && girl_name!=""){
cout<<max_girl_socre-min_boy_score;
}
else{
cout<<"NA";
}
return 0;
}