1.题目介绍
2.考察点,难度
字符串处理类,string相等判断,难度易
3.解题代码
#include <bits/stdc++.h>
using namespace std;
int main(){
freopen("D:\\PAT\\Clion\\in.txt","r",stdin);
int N;
cin>>N;
string fn="0",mn="0",fc,mc;
int fs=-1,ms=101,flag=0;
for(int i=0;i<N;i++){
string a,b,c;
int d;
cin>>a>>b>>c>>d;
if(b=="M" && d<ms){
ms=d;
mc=c;
mn=a;
}
if(b=="F" && d>fs){
fs=d;
fc=c;
fn=a;
}
}
if(fn=="0"){
cout<<"Absent"<<endl;
flag=1;
}
else{
cout<<fn<<" "<<fc<<endl;
}
if(mn=="0"){
cout<<"Absent"<<endl;
flag=1;
} else{
cout<<mn<<" "<<mc<<endl;
}
flag?cout<<"NA"<<endl:cout<<fs-ms<<endl;
return 0;
}
4.原题地址
https://pintia.cn/problem-sets/994805342720868352/problems/994805453203030016