簡要思路:就是讓你做集合的運算,輸出結果中的元素。當時用了數組,結果超時了,最後在室友的提醒下用了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 }