# 题解 | #记票统计#

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

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

int main() {
int n;
cin >> n;
vector<string> houxuanren;
for (int i = 0;i < n;i++)
{
string a;
cin >> a;
houxuanren.push_back(a);
}

int m;
cin >> m;
vector<string> xuanpiao;
for (int i = 0;i < m;i++)
{
string a;
cin >> a;
xuanpiao.push_back(a);
}

//unordered_map<string ,int> tongji;

// for (auto it : houxuanren)
// {
//     tongji[it] = 0;         //初始化map，一个候选人对应一个选票
// }

vector<pair<string, int>> tongji(houxuanren.size());

for (int i = 0; i < houxuanren.size(); ++i)
{
tongji[i] = make_pair(houxuanren[i], 0);
}

for (int i = 0;i < xuanpiao.size();i++)
{
for (int j = 0;j < houxuanren.size();j++)
{
if (xuanpiao[i] == houxuanren[j])
{
tongji[j].second += 1;
}
}
}
for (auto it : tongji)
{
cout << it.first << " : " << it.second << endl;
}

int wuxiao = 0;
for (auto it : tongji)
{
wuxiao += it.second;
}
cout << "Invalid : " << (m - wuxiao) ;
}
// 64 位输出请用 printf("%lld")
```