题解 | #记票统计#
记票统计
https://www.nowcoder.com/practice/3350d379a5d44054b219de7af6708894
// HJ94 计票统计.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, n;
vector<string>str;
vector<string>match;
while (cin >> m)
{
for (int i = 0; i < m; i++)
{
string x;
cin >> x;
str.push_back(x);
}
cin >> n;
for (int i = 0; i < n; i++)
{
string x;
cin >> x;
match.push_back(x);
}
int l1 = str.size(), l2 = match.size();
vector<int>num(l1);
/*for (auto c : str)
cout << c << endl;
for (auto x : match)
cout << x << endl;*/
for (int i = 0; i < str.size(); i++)
{
for (int j = 0; j < match.size(); j++)
{
if (str[i] == match[j])
{
num[i]++;
}
}
}
int sum = 0;
for (auto c : num)
{
sum += c;
}
for (int i = 0; i < l1; i++)
{
cout << str[i] << " : " << num[i] << endl;
}
cout << "Invalid" << " : " << n - sum << endl;
}
return 0;
}
