题解 | #记票统计#

记票统计

http://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894

//vector + unordered_map

#include<vector>
#include<unordered_map>
using namespace std;
int main(){
    int n;
    while(cin >> n){
        string str;
        vector<string> people;
        unordered_map<string, int> mp;
        for(int i = 0 ; i < n; i ++ ){
             cin >> str;
             people.emplace_back(str);
             mp[str] = 0;
        }
        int n2;
        cin >> n2;
        int Invalid = 0;
        for(int i = 0 ; i < n2; i ++ ){
             cin >> str;
             if(mp.find(str) != mp.end()){
                 mp[str] ++;
             }else{
                 Invalid ++ ;
             }
        }
        for(int i = 0 ; i < n; i ++ ){
            cout << people[i] <<" : " << mp[people[i]] <<endl;
        }
        cout << "Invalid" <<" : " << Invalid <<endl;
    }
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务