pta 1100 校慶 (25 分)
1100 校慶 (25 分)
2019 年浙江大學(xué)將要慶祝成立 122 周年。為了準備校慶,校友會收集了所有校友的身份證號?,F(xiàn)在需要請你編寫程序,根據(jù)來參加校慶的所有人士的身份證號,統(tǒng)計來了多少校友。
輸入格式:
輸入在第一行給出不超過 105 的正整數(shù) N,隨后 N 行,每行給出一位校友的身份證號(18 位由數(shù)字和大寫字母X組成的字符串)。題目保證身份證號不重復(fù)。
隨后給出前來參加校慶的所有人士的信息:首先是一個不超過 105 的正整數(shù) M,隨后 M 行,每行給出一位人士的身份證號。題目保證身份證號不重復(fù)。
輸出格式:
首先在第一行輸出參加校慶的校友的人數(shù)。然后在第二行輸出最年長的校友的身份證號 —— 注意身份證第 7-14 位給出的是 yyyymmdd 格式的生日。如果沒有校友來,則在第二行輸出最年長的來賓的身份證號。題目保證這樣的校友或來賓必是唯一的。
輸入樣例:
5
372928196906118710
610481197806202213
440684198612150417
13072819571002001X
150702193604190912
6
530125197901260019
150702193604190912
220221196701020034
610481197806202213
440684198612150417370205198709275042
輸出樣例:
3150702193604190912
代碼:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
struct node{
string s;
int id;
bool operator <(const node& a)const{
if(id != a.id) return id > a.id;
return s.substr(6, 8) < a.s.substr(6,8);
}
};
int main() {
int n, m;
cin >> n;
unordered_set<string> st;
string s;
for(int i = 0; i < n; i++) {
cin >> s;
st.insert(s);
}
cin >> m;
int count = 0;
vector<node> res;
for(int i = 0; i < m; i++) {
cin >> s;
if(st.count(s)){
count++;
res.push_back({s, 1});
}else{
res.push_back({s, 0});
}
}
sort(res.begin(), res.end());
cout<<count<<endl;
cout<<res[0].s<<endl;
return 0;
}
評論
圖片
表情

