题解 | #记票统计#

记票统计

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

#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    string str;
    unordered_map<string, int> contribute;
    vector<string> v;
    for(int i = 0; i < n; ++i){
        cin >> str;
        contribute[str] = 0;
        v.push_back(str);
    }
    v.push_back("Invalid");
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> str;
        if( contribute.find(str) != contribute.end() ){
            contribute[str] ++;
        }else{
            contribute["Invalid"] ++;
        }
    }
    for(auto it : v){
        cout << it << " : " << contribute[it] << endl; 
    }


}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务