解题思路:注意当违禁物品编号为0123时,输出时也要输出0123
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,sum=0,index=0,num;
string name;
int ban[10000];
cin>>n>>m;
memset(ban,0,sizeof(ban));
for(int i=1;i<=m;i++){
cin>>num;
ban[num]=1;
}
for(int i=1;i<=n;i++){
cin>>name;
int number,ssum=0;
cin>>number;
for(int j=1;j<=number;j++){
cin>>num;
if(ban[num]==1&&ssum==0){
cout<<name<<":";
printf(" %04d", num);
ssum++;
index++;
}
else if(ban[num]==1&&ssum!=0){
printf(" %04d", num);
ssum++;
index++;
}
}
if(ssum!=0){
sum++;
cout<<endl;
}
}
cout<<sum<<" "<<index;
}
运行结果: