1036 Boys vs Girls (25 分)
题解:
模拟题 根据题目要求 每次输入数据更新男生最后一名的成绩 跟第一名女生成绩
最后判断 男女生是否有
代码:
#include<iostream>
using namespace std;
int main(){
int n;
string girl_name, girl_id;
int girl_score;
string boy_name, boy_id;
int boy_score;
cin>>n;
for(int i=0;i<n;i++){
string name,sex,id;
int score;
cin>>name>>sex>>id>>score;
if(sex=="F"){
if(girl_name.empty()||girl_score<score){
girl_name = name;
girl_id = id;
girl_score = score;
}
}else{
if(boy_name.empty()||boy_score>score){
boy_name = name;
boy_id = id;
boy_score = score;
}
}
}
if(girl_name.empty()) puts("Absent");
else cout<<girl_name<<' '<<girl_id<<endl;
if(boy_name.empty()) puts("Absent");
else cout<<boy_name<<' '<<boy_id<<endl;
if(girl_name.empty()||boy_name.empty()) cout<<"NA"<<endl;
else cout<<girl_score-boy_score<<endl;
}