解题思路:
(1)map
#include<iostream>
#include<map>
using namespace std;
auto Find(map<int,pair<string,int>> &mp,string &s) {
for(auto it=mp.begin();it!=mp.end();it++) {
if(it->second.first==s) return it;
}
return mp.end();
}
int main() {
int n,m;
string s1,s2;
while(cin>>n) {
int count=0;
map<int,pair<string,int>> mp;
for(int i=0;i<n;i++) {
cin>>s1;
mp[i]={s1,0};
}
cin>>m;
for(int i=0;i<m;i++) {
cin>>s2;
if(Find(mp,s2)==mp.end()) count++;
else Find(mp,s2)->second.second++;
}
for(auto it=mp.begin();it!=mp.end();it++) {
cout<<it->second.first<<" : "<<it->second.second<<endl;
}
cout<<"Invalid : "<<count<<endl;
}
return 0;
}