Sicily-A-B

简要思路:就是让你做集合的运算,输出结果中的元素。当时用了数组,结果超时了,最后在室友的提醒下用了set,简直不要太好用!

输出有点坑爹,就是元素和元素间要有空格,最后一个元素没有空格。

还要考虑当结果是空集的特殊情况。

 1 // Problem#: 19572
 2 // Submission#: 5037010
 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
 6 #include<iostream>
 7 #include<map>
 8 #include<string>
 9 #include<cstring>
10 #include<set>
11 using namespace std;
12 int main() {
13     int T;
14     cin >> T;
15     while(T--) {
16         set<int> jihe; 
17         int m;
18         cin >> m;
19         while(m--){
20             int k;
21             cin >> k;
22             jihe.insert(k);
23         }
24         int n;
25         cin >> n;
26         while(n--) {
27             int j;
28             cin >> j;
29             if (jihe.count(j)!=0) {
30                 jihe.erase(j);
31             }
32         }
33         if (jihe.size() == 0) {
34             cout << endl;
35             continue;
36         }
37         set<int>::iterator it;
38         for (it = jihe.begin();it!=jihe.end();++it) {
39             if (it == jihe.begin()) {
40                 cout << *it;
41             } else {
42                 cout<< " " << *it;
43             }
44         }
45         cout << endl;
46         
47     }
48 }                 

 

转载于:https://www.cnblogs.com/SYSU-Bango/p/6307037.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值