L1-020 帅到没朋友

 

#include <iostream>
using namespace std;

int a[100000];
int main() {
	int n;
	cin >> n;
	int x, id;
	while(n--) {
		cin >> x;
		if (x >= 2) {
			while(x--) {
				cin >> id;
				a[id] = 1;
			}
		} else
			cin >> id;
	}
	
	int m, flag = 0;
	cin >> m;
	while(m--) {
		cin >> id;
		if (a[id] != 1) {
			if (flag)
				cout << " ";
			printf("%05d", id);
			flag = 1;
			a[id] = 1;
		}
	}
	if (flag == 0)
		printf("No one is handsome");
	return 0;
}

在set中放入所有有朋友的集合,当然要定义成set < string > s,要不然还是得考虑域宽的问题。然后用,s.insert(str)来进行字符串的插入,s.find(str)==s.end()表示没有找到,大致思路都差不多。下面代码还有很多有趣的地方,可以耐心看一看

#include <bits/stdc++.h>
using namespace std;
int n, k, m, x;
bool flag;
set<int>s, ans;

int main() {
	cin >> n;
	while (n--) {
		cin >> k;
		if (k >= 2)
			while (k--) {
				cin >> x;
				s.insert(x);
			} else
			cin >> x;
	}
	cin >> m;
	while (m--) {
		cin >> x;
		if (s.find(x) == s.end() && ans.find(x) == ans.end()) {
			ans.insert(x);
			if (flag)
				cout << ' ';
			flag = 1;
			cout << setw(5) << setfill('0') << x;
		}
	}
	if (!flag)
		cout << "No one is handsome";
	return cout << endl, 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值