英文题目
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID’s of all her alumni. Now your job is to write a program to count the number of alumni
among all the people who come to the celebration.
Input Specification:
Each input file contains one test case. For each case, the first part is about the information of all the alumni. Given in the first line is a positive integer NNN (≤105).
Then NNN lines follow, each contains an ID number of an alumnus. An ID number is a string of 18 digits or the letter X. It is guaranteed that all the ID’s are distinct.
The next part gives the information of all the people who come to the celebration.
Again given in the first line is a positive integer MMM(≤105). Then MMM lines follow, each contains an ID number of a guest. It is guaranteed that all the ID’s are distinct.
Output Specification:
First print in a line the number of alumni among all the people who come to the celebration. Then in the second line, print the ID of the oldest alumnus – notice that the 7th - 14th digits of the ID gives one’s birth date. If no alumnus comes, output the ID of the oldest guest instead. It is guaranteed that such an alumnus or guest is unique.
Sample Input:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
1
2
3
4
5
6
7
8
9
10
11
12
13
Sample Output:
3
150702193604190912
中文题目
7-5 校庆 (25 分)
2019 年浙江大学将要庆祝成立 122 周年。为了准备校庆,校友会收集了所有校友的身份证号。现在需要请你编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。
输入格式:
输入在第一行给出不超过 10^5 的正整数 N,随后 N 行,每行给出一位校友的身份证号(18 位由数字和大写字母X组成的字符串)。题目保证身份证号不重复。
随后给出前来参加校庆的所有人士的信息:首先是一个不超过 10^5 的正整数 M,随后 M 行,每行给出一位人士的身份证号。题目保证身份证号不重复。
输出格式:
首先在第一行输出参加校庆的校友的人数。然后在第二行输出最年长的校友的身份证号 —— 注意身份证第 7-14 位给出的是 yyyymmdd 格式的生日。如果没有校友来,则在第二行输出最年长的来宾的身份证号。题目保证这样的校友或来宾必是唯一的。
输入样例:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
输出样例:
3
150702193604190912
分析
这道题没用set或者unorder set存校友名录会超时。
满分代码
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
int n,m,cnt=0;
cin>>n;
getchar();
string s,old="20190302",ans;
set<string> st;
for(int i=0;i<n;i++){
getline(cin,s);
st.insert(s);
}
cin>>m;
getchar();
for(int i=0;i<m;i++){
getline(cin,s);
set<string>::iterator it;
if(st.find(s)!=st.end()){
cnt++;
}
if(s.substr(6,8)<old){
old=s.substr(6,8);
ans=s;
}
}
cout<<cnt<<endl;
cout<<ans;
return 0;
}
来源:CSDN
作者:qiiingc
链接:https://blog.csdn.net/allisonshing/article/details/104274669