输入样例:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417
370205198709275042
输出样例:
3
150702193604190912
solution
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){int n, m, ans = 0;string s, old1 = "null", old2 = "null";map<string, int> mp;//mp[s]==1则身份证为s的来宾是校友cin >> n;for(int i = 0; i < n; i++){cin >> s;mp[s] = 1;}cin >> m;for(int i = 0; i < m; i++){cin >> s;if(old1.size() < 10 || old1.substr(6, 8) > s.substr(6, 8)) old1 = s;//年龄大==>出生年月小if(mp[s]){ans++;if(old2.size() < 10 || old2.substr(6, 8) > s.substr(6, 8)) old2 = s;}}if(ans == 0) cout << ans << endl << old1;//没有校友来,则输出最年长的来宾else cout << ans << endl << old2;//有校友来,则输出最年长的校友return 0;
}