1065 单身狗 解题代码测试结果问题整理 解题代码 #include<iostream> #include<unordered_map> #include<set> #include<string> using namespace std; int main() { int n; cin >> n; string a, b; unordered_map<string, string> m; for (int i = 0; i < n; i++) { cin >> a >> b; m[a] = b; m[b] = a; } cin >> n; string str; set<string> s; unordered_map<string, bool> mm; for (int i = 0; i < n; i++) { cin >> str; s.insert(str); mm[m[str]] = true; } int cnt = 0; for (auto x : s) if (!mm[x]) cnt++; cout << cnt << endl; bool flag = false; for (auto x : s) { if (!mm[x]) { if (flag == false) flag = true; else cout << " "; cout << x; } } return 0; } 测试结果 问题整理 1.基础题目。