标签:result class col flag div vector push size tor
未使用set的未AC版
1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<set> 5 #include<iterator> 6 7 using namespace std; 8 9 int main() { 10 int N, k, M, flag; 11 cin >> N; 12 vector<vector <string>> id; 13 string s; 14 set<string> result; 15 for (int i = 0; i < N; i++) { 16 cin >> k; 17 vector<string> temp; 18 for (int j = 0; j < k; j++) { 19 cin >> s; 20 temp.push_back(s); 21 } 22 id.push_back(temp); 23 temp.clear(); 24 } 25 26 cin >> M; 27 for (int i = 0; i < M; i++) { 28 flag = 0; 29 cin >> s; 30 for (int j = 0; j < id.size(); j++) { 31 for (int p = 0; p < id[j].size(); p++) { 32 if (s == id[j][p]) 33 flag = 1; 34 } 35 } 36 if (flag == 0) 37 result.insert(s); 38 } 39 40 if (result.size() == 0) 41 cout << "No one is handsome" << endl; 42 else { 43 set<string>::iterator iter = result.begin(); 44 45 while (iter != result.end()) 46 { 47 cout << *iter << " "; 48 ++iter; 49 } 50 } 51 52 system("pause"); 53 return 0; 54 }
全部使用set的AC版
1 #include <iostream> 2 #include <set> 3 using namespace std; 4 int main() { 5 int a, b, c; 6 cin >> a; 7 set<string> s, ans; 8 string str; 9 for(int i = 0; i < a; i++) { 10 cin >> b; 11 if(b >= 2) { 12 for(int j = 0; j < b; j++) { 13 cin >> str; 14 s.insert(str); 15 } 16 } else { 17 cin >> str; 18 } 19 } 20 cin >> c; 21 int flag = 0; 22 for(int i = 0; i < c; i++) { 23 cin >> str; 24 if(s.find(str) == s.end() && ans.find(str) == ans.end()) { 25 ans.insert(str); 26 if(flag == 1) 27 cout << " "; 28 cout << str; 29 flag = 1; 30 } 31 } 32 if(flag == 0) 33 cout << "No one is handsome"; 34 return 0; 35 }
标签:result class col flag div vector push size tor
原文地址:https://www.cnblogs.com/Frances-CY-FKYM/p/12538447.html