Skip to main content

4269.校庆

思路

代码

#include <bits/stdc++.h>

using namespace std;

int n, m;
unordered_map<string, int> sch;
vector<string> res;

int main() {
cin >> n;

for (int i = 0; i < n; i++) {
string t;
cin >> t;
sch[t] = 1;
}

string a, b;

cin >> m;

while (m--) {
string t;
cin >> t;
string name = t;
if (sch.count(t) != 0) {
res.push_back(t);
// 记录参加校庆的校友最年长的身份证
if (a.empty() || a.substr(6, 8) > name.substr(6, 8))
a = name;
}
// 记录出席来宾中最年正的身份证
if (b.empty() || b.substr(6, 8) > name.substr(6, 8))
b = name;
}
// 输出参加校庆的校友
cout << res.size() << endl;

if (res.size()) {
cout << a << endl;
} else {
cout << b << endl;
}

return 0;
}