华为机试-记票统计(较难)

记票统计

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

题目描述

请实现一个计票统计系统。你会收到很多投票,其中有合法的也有不合法的,请统计每个候选人得票的数量以及不合法的票数。
本题有多组样例输入。

不知道华为机试的难度是怎么区分的

#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int main(){
    int num_name,num_choice;
    while(cin>>num_name){
        vector<string> name;//保存有哪些名字(vector可以保留顺序)
        unordered_map<string,bool> flag;//用来后面判断输入的名字是否合法
        unordered_map<string,int> num;//统计每个人的得票
        int wrong=0;
        while(num_name--){
            string s;
            cin>>s;
            name.push_back(s);
            flag[s]=true;
        }
        cin>>num_choice;
        while(num_choice--){
            string s;
            cin>>s;
            if(flag[s]==true)
                num[s]++;
            else wrong++;
        }

        for(string i:name)
            cout<<i<<" : "<<num[i]<<endl;
        cout<<"Invalid : "<<wrong<<endl;
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
评论
1
3
分享

创作者周榜

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