PAT 1157Anniversary (25 分)
输入样例
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
输出样例
3
150702193604190912
- 大致题意
- 思路
- AC代码
1.大致题意
统计一下有多少人来参加校友庆祝会。
2.思路
统计校友会中多少个来参加典礼的然后输出年龄最大的人(id中第7-14位数字);如果没有校友来参加,输出参会人员最年长的id
(1)首先输入id,每个id是由18位组成,或为数字,或为字母X,
题目保证所有输入的id不重复
(2)第二个部分是来参会的人员及其id
注意一个大坑:没有校友会的人来参加也要输出0
3.AC代码
#include<bits/stdc++.h>
using namespace std;
string get_age(string s)
{
string age=s.substr(6,8);
return age;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
{
freopen("2.txt","r",stdin);
}
#endif
int n,m;
string str,oldest_age="9999",old_people;
cin>>n;
map<string,int>mp;
for(int i=0;i<n;i++)
{
cin>>str;
mp[str]=1;
string now_age= get_age(str);
if(now_age<oldest_age)
{
oldest_age=now_age;
old_people=str;
}
}
cin>>m;
int ans=0;
string o2="9999",op;
for(int i=0;i<m;i++)
{
cin>>str;
string now=get_age(str);
if(now<o2)
{
o2=now;
op=str;
}
if(mp[str]==1) ans++;
}
if(ans!=0)
{
cout<<ans<<endl;
cout<<old_people<<endl;
}
if(ans==0)
{
cout<<0<<endl;
cout<<op<<endl;
}
return 0;
}
喵~