L1-1 帅到没朋友 (20分)

在这里插入图片描述

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888

输出样例:

10000 88888 23333
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


bool havefrind[110000] = {
    
    false};
bool visit[110000] = {
    
    false};//不重复判断
vector<int> a;
int main()
{
    
    
	int n, id;
	cin >> n;
	while(n--)
	{
    
    
		int x;
		cin >> x;
		/*if(x == 1) //朋友圈只有自己一个人 没朋友
		{
			cin >> id; 
			havefrind[id] = false;
		} 
		else
		{
			while(x--)
			{
				cin >> id;
				havefrind[id] = true; 
			}
		}*/
		for(int i = 0; i < x; i++)
		{
    
    
			cin >> id;
			if(x > 1) havefrind[id] = true;
		}
	}
	int m;
	cin >> m;
	while(m--)
	{
    
    
		cin >> id;
		a.push_back(id);//放需要判断的m个人
	}
	int cnt = 0;
	bool flag = false;//控制空格格式
	for(int i = 0; i < a.size();i++)
	{
    
    
		int now = a[i];
		if(havefrind[now] == true) cnt++;//只要有朋友就算数不管是否重复判断
		else if(havefrind[now] == false && visit[now] == false)
		{
    
    
			if(flag == true) cout << " ";
			printf("%05d",now);
			visit[now] = true;
			flag = true;
		}	
	}
	if(cnt == a.size()) cout << "No one is handsome";
return 0;
}

猜你喜欢

转载自blog.csdn.net/moumoumouwang/article/details/109630143