解题思路:利用STL unordered_set保存集合A和C, list保存集合B, 判断集合B中也在A中但不在C中的元素。
注意事项:题意要求按B输入顺序输出,所以需要用有序列表保存B中的元素。
参考代码:
#include<iostream> #include<string> #include<unordered_set> #include<list> using namespace std; int main() { int A, B, C; while (cin >> A >> B >> C) { string s; unordered_set<string> a; while (A--) { cin >> s; a.insert(s); } list<string> b; while (B--) { cin >> s; b.push_back(s); } unordered_set<string> c; while (C--) { cin >> s; c.insert(s); } bool spy = false; for (string s : b) { if (a.find(s) != a.end() && c.find(s) == c.end()) { cout << s << ' '; spy = true; } } if (!spy) cout << "No enemy spy"; cout << '\n'; } return 0; }
0.0分
0 人评分
钟神赛车 (C语言代码)浏览:880 |
妹子杀手的故事 (C语言代码)浏览:692 |
C语言考试练习题_排列 (C语言代码)浏览:1330 |
弟弟的作业 (C++代码)浏览:1306 |
C语言训练-数字母 (C语言代码)浏览:586 |
分糖果 (C++代码)浏览:1453 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:575 |
C语言训练-大、小写问题 (C语言代码)浏览:615 |
WU-拆分位数 (C++代码)浏览:790 |
母牛的故事 (C语言代码)浏览:1429 |