#include <iostream>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
map<string,int>str;
int n,m;
scanf("%d %d",&n,&m);
string t;
for(int i=0;i<n;++i){
cin>>t;
if(str.count(t)==0){
str[t]=1;
}else{
str[t]+=1;
}
}
for(int i=0;i<n;i++){
cin>>t;
cout<<t<<" "<<str.count(t)<<endl;
}
return 0;
}
4 3
qwe
eee
qwer
asdf
qwe
qwe 1
eee
eee 1
qqqqq
qqqqq 0
原文:https://www.cnblogs.com/huzhengyu/p/14398174.html