关键:用一个数组保存是否有朋友,在朋友圈人数>1时依次对数组进行修改即可。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k,m,id;
bool handsome[100000][2];
for(int i=0;i<100000;i++)
{
handsome[i][0]=true;//是否帅气
handsome[i][1]=false;//是否已被输出
}
cin>>n;
for(int i=0;i<n;i++)
{
cin>>k;
if(k==1) {cin>>id; continue;}//----------------
for(int j=0;j<k;j++)
{
cin>>id;
handsome[id][0]=false;
}
}
bool flag=true,first=true;
cin>>m;
for(int i=0;i<m;i++)
{
cin>>id;
if(handsome[id][0]&&handsome[id][1]==false)
{
if(first) {printf("%05d",id); first=false;}
else printf(" %05d",id);
flag=false;
handsome[id][1]=true;
}
}
if(flag) cout<<"No one is handsome";
return 0;
}
/*2
1 00011
4 22222 33333 22222 22222
3
00011 44444 22222*/
- 用continue的时候,看看循环内continue下面还有没有其他输入语句。不要忘了处理它们。
- 用int表示标号并输出的时候,注意需不需要加前导0.
printf("%05d",id);