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.
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 N (≤105). Then N 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 M (≤105). Then M lines follow, each contains an ID number of a guest. It is guaranteed that all the ID’s are distinct.
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.
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
3
150702193604190912
题目大意:为了准备校庆,校友会收集了所有校友的身份证号。编写程序,根据来参加校庆的所有人士的身份证号,统计来了多少校友。输入在第一行正整数N,随后N行,每行给出一位校友的身份证号(18位由数字和大写字母X组成的字符串)。题目保证身份证号不重复。随后给出前来参加校庆的所有人士的信息:首先是一个不超过正整数M,随后M行,每行给出一位人士的身份证号。题目保证身份证号不重复。首先在第一行输出参加校庆的校友的人数。然后在第二行输出最年长的校友的身份证号——注意身份证第7-14位给出的是yyyymmdd格式的生日。如果没有校友来,则在第二行输出最年长的来宾的身份证号。题目保证这样的校友或来宾必是唯一的。
分析:使用容器set
- #include
- #include
- using namespace std;
- int n, m, cnt;
- string temp, smallx = "99999999", smalla = "99999999", ansx, ansa;
- set
record; - int main() {
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> temp;
- record.insert(temp);
- }
- cin >> m;
- for (int i = 0; i < m; i++) {
- cin >> temp;
- if (record.count(temp)) {
- cnt++;
- if (smallx > temp.substr(6, 8)) {
- smallx = temp.substr(6, 8);
- ansx = temp;
- }
- }
- if (smalla > temp.substr(6, 8)) {
- smalla = temp.substr(6, 8);
- ansa = temp;
- }
- }
- cout << cnt << endl;
- if (cnt) cout << ansx;
- else cout << ansa;
- return 0;
- }