分析
代码
#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;
}
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cctype>
#include <unordered_map>
#include <map>
using namespace std;
const int N = 105;
typedef pair<int, string> PII;
int main() {
unordered_map<string, bool> mp;
string oldalumni="99999999", oldguest="99999999";
string olda, oldg;
int num = 0;
int n;
cin>>n;
string str, tmp, t;
for(int i = 0; i < n; i++){
cin>>str;
mp[str]= true;
}
int m;
cin>>m;
for(int i = 0; i < m; i++){
cin>>str;
t = str.substr(6, 8);
if(mp[str]){
if(t < oldalumni){
oldalumni = t;
olda = str;
}
num++;
}
if(t < oldguest){
oldguest = t;
oldg = str;
}
}
cout<<num<<endl;
if(num == 0) cout<<oldg<<endl;
else cout<<olda<<endl;
return 0;
}