2019-PTA模拟赛-L1-1 帅到没朋友
输入样例1:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888
输出样例1:
10000 88888 23333
输入样例2:
3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111
输出样例2:
No one is handsome
思路:
一个人一个圈子的直接不计入,当作不存在
大于或等于一个人的圈子,在vis数组中做标记
统计不在vis中的人即可
Code:
#include<bits/stdc++.h> // 万能头
using namespace std;
bool vis[100010]; //记录有朋友的人
int main(){
int N;
cin >> N;
while(N--){
int K;
cin >> K;
if(K == 1){
int rub;
cin >> rub; //这里必须做一次输入
continue;
}else{
while(K--){
int id;
cin >> id;
vis[id] = true; //有朋友的在vis中做标记
}
}
}
int M;
cin >> M;
vector<int> res; //方便处理最后一个空格
while(M--){
int search;
cin >> search;
if(!vis[search]){ //题目要求查的是没朋友的
res.push_back(search);
vis[search] = true; //打上标记----去重
}
}
if(res.empty()){ //全都有朋友情况
cout << "No one is handsome";
return 0;
}
for(auto i = res.begin(); i != res.end(); i++){
printf("%05d", *i); //五个宽度用0补齐
if(i != res.end() - 1) cout << ' ';
}
return 0;
}