#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
int main(){
int N, M, cnt;
std::string oldestAlumni, oldestGuest, id;
std::unordered_map<std::string, int> mp;
bool flag;
std::cin >> N;
for(int i = 0; i < N; ++i){
std::cin >> id;
mp[id] = 1;
}
oldestAlumni = "999999999999999999";
oldestGuest = "999999999999999999";
cnt = 0;
std::cin >> M;
flag = false;
for(int i = 0; i < M; ++i){
std::cin >> id;
if(mp[id] == 1){
flag = true;
cnt++;
if(id.substr(6, 8) < oldestAlumni.substr(6, 8)){
oldestAlumni = id;
}
}
if(!flag && id.substr(6, 8) < oldestGuest.substr(6, 8)){
oldestGuest = id;
}
}
std::cout << cnt << std::endl;
if(flag){
std::cout << oldestAlumni;
} else{
std::cout << oldestGuest;
}
return 0;
}
题目如下:
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 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.
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
Sample Output:
3
150702193604190912
这是一个C++程序,用于处理输入的校友和嘉宾ID,计算参加庆典的校友数量,并找出最年长的校友或嘉宾的ID。程序首先读取校友的ID建立映射,然后处理嘉宾ID,找出校友并更新最年长校友的记录,如果没有校友,则选择最年长的嘉宾。
&spm=1001.2101.3001.5002&articleId=130595106&d=1&t=3&u=1c0fd0b567ed4142913fe32bf76f8eb8)
667

被折叠的 条评论
为什么被折叠?



