题解 | #记票统计#
记票统计
http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
C++实现,map容器与vector容器搞定
#include<iostream> #include<string> #include<vector> #include<map> using namespace std; int main() { int n; while(cin>>n){ string c; int arr[100]={0}; map<string,int> mp; vector<string> v; for(int i=0;i<n;++i){ cin>>c; mp.insert(make_pair(c, 0)); v.push_back(c); } int m; int invalid=0; cin>>m; string str; for(int i=0;i<m;++i){ cin>>str; if(mp.find(str)!=mp.end()){ mp[str]++; }else{ invalid++; } } for(auto it:v){ cout<<it<<" : "<<mp.find(it)->second<<endl; } cout<<"Invalid : "<<invalid<<endl; } return 0; }