解题代码
#include<cstdio>
#include<string>
#include<unordered_map>
using namespace std;
int main() {
unordered_map<string, bool> mp;
int n, m, k, cnt, sum = 0, peo = 0;
string temp, item, name;
temp.resize(4);
item.resize(4);
name.resize(4);
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%s", temp.c_str());
mp[temp] = true;
}
for (int i = 0; i < n; i++) {
cnt = 0;
scanf("%s", name.c_str());
scanf("%d", &k);
for (int j = 0; j < k; j++) {
scanf("%s", item.c_str());
if (mp[item]) {
cnt++;
if (cnt == 1) printf("%s: %s", name.c_str(), item.c_str());
else printf(" %s", item.c_str());
}
}
if (cnt) {
printf("\n");
peo++;
sum += cnt;
}
}
printf("%d %d", peo, sum);
return 0;
}
测试结果
问题整理
1.基础题目。
2.代码风格日益懒散。