AcWing 4269. 校庆
不是道难题,但是自己的解法一直被卡时间,看了一下y总的视频,果然工具好用,unordered_set,优先集合,内部是无序存储的元素,但是可以快速访问,比set要快,这里用来存储所有校友
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
string a, b;
int main()
{
unordered_set<string> Hash;
cin>>n;
for(int i = 0; i < n; i ++ ){
string name;
cin>>name;
Hash.insert(name);
}
int cnt = 0;
cin>>m;
while(m -- ){
string name;
cin>>name;
if(Hash.count(name)){
cnt ++ ;
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<<cnt<<endl;
if(cnt){
cout<<a<<endl;
}
else cout<<b<<endl;
return 0;
}