显示代码纯文本
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
map<int,string>n_sch;
map<string,int>peo;
map<string,int>sch;
int bl[233];
int n,k;
string a,b;
int cnt;
int w[233],sum[233];
inline int gg(){
freopen("sakinani.in","r",stdin);
freopen("sakinani.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>a>>b;
w[i]=1;
peo[a]=i;
if(!sch[b])
sch[b]=++cnt,n_sch[cnt]=b;
bl[i]=sch[b];
}
scanf("%d",&k);
for(int i=1;i<=k;i++){
cin>>a;
if(peo.count(a))
w[peo[a]]=2;
}
while(cin>>a){
if(!peo.count(a))
continue;
sum[bl[peo[a]]]+=w[peo[a]];
}
int mx(0),ans;
for(int i=1;i<=cnt;i++){
if(sum[i]==mx&&n_sch[i]<n_sch[ans])
ans=i;
if(sum[i]>mx)
mx=sum[i],ans=i;
}
cout<<n_sch[ans];
return 0;
}
int K(gg());
int main(){;}