2019-spring-7-2 Anniversary
作者:
Kue
,
2020-08-20 21:45:49
,
所有人可见
,
阅读 464
PAT hash算法
#include <iostream>
#include <cstring>
#include <vector>
#include <unordered_map>
using namespace std;
unordered_map<string,bool> visit;
int main()
{
int m, n;
cin >> m;
string str;
bool flag = true, f1 = true;
while (m --)
{
cin >> str;
visit[str] = true;
}
cin >> n;
vector<string> a;
string id_all, id_ali, min, min_aln;
while (n --)
{
cin >> str;
string sstr = str.substr(6, 8);
if (flag) min = sstr, flag = false, id_all = str;
else{
if (sstr < min) min = sstr, id_all = str;
}
if (visit[str])
{
a.push_back(sstr);
if (f1) min_aln = sstr, f1 = false, id_ali = str;
else
{
if (sstr < min_aln) min_aln = sstr, id_ali = str;
}
}
}
cout << a.size() << "\n";
if (a.size() > 0) cout << id_ali;
else cout << id_all;
}