代码:
#include<bits/stdc++.h>
using namespace std;
struct people {
string id, birthday;
};
bool cmp(people a, people b) {
return a.birthday < b.birthday;
}
int main() {
int n;
cin >> n;
unordered_map<string, int> alumni;
for(int i = 0; i < n; i++) {
string temp;
cin >> temp;
alumni[temp] = 1;
}
int sum = 0;
vector<people> participants;
vector<people> alumniInParticipants;
int m;
cin >> m;
for(int i = 0; i < m; i++) {
string temp;
cin >> temp;
if(alumni.find(temp) != alumni.end()) {
alumniInParticipants.push_back({temp, temp.substr(7, 7)});
}
participants.push_back({temp, temp.substr(7, 7)});
}
cout << alumniInParticipants.size() << endl;
if(alumniInParticipants.size() != 0) {
sort(alumniInParticipants.begin(), alumniInParticipants.end(), cmp);
cout << alumniInParticipants[0].id << endl;
}
else {
sort(participants.begin(), participants.end(), cmp);
cout << participants[0].id << endl;
}
return 0;
}
总结: spp中的substr是起始位置加长度
|