Sicily-A-B。本站提示廣大學習愛好者:(Sicily-A-B)文章只能為提供參考,不一定能成為您想要的結果。以下是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 }