代码:
#include<bits/stdc++.h>
using namespace std;
set<int> things;
int main() {
int n,m,x,cnt_s=0,cnt_n=0;
/*
n:学生人数
m:需要被查缴的物品种类数
x:中间变量
cnt_s:存在问题的学生的总人数
cnt_n:被查缴物品的总数
*/
cin>>n>>m;
for(int i=0; i<m; i++) { //输入M个需要被查缴的物品编号
cin>>x;
things.insert(x);
}
for(int i=0; i<n; i++) {
int k; //个人物品数量
string name;
vector<int> res;
cin>>name>>k;
for(int j=0; j<k; j++) {
cin>>x;
if(things.find(x)!=things.end()) { //能找到
res.push_back(x);
cnt_n++;
}
}
if(res.size()) {
cnt_s++;
cout<<name<<": ";
for(int h=0; h<res.size(); h++) {
if(h>0) cout<<" ";
printf("%04d",res[h]);
}
cout<<endl;
}
}
cout<<cnt_s<<" "<<cnt_n;
return 0;
}
简单题