题目链接
silu
题目要求对参加聚会的人进行判断
对单身狗进行保留
考虑到删除操作使迭代器失效是一个头疼的问题
那就不删吧
要么就不用容器,就用一个静态数组存储参加聚会的人
都是在避免删除操作留下的烂摊子
代码
using namespace std;
#include<set>
#include<map>
#include <iomanip>
#include <iostream>
int n,p, q;
map<int, int>couple;
set<int>party, result;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p >> q;
couple[p] = q;
couple[q] = p;
}
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p;
party.insert(p);
}
for (auto i = party.begin(); i != party.end(); i++) {
if (couple.find(*i) == couple.end() || party.find(couple[*i]) == party.end()) {
result.insert(*i);
}
}
cout << result.size() << endl;
for (auto i = result.begin(); i != result.end(); i++) {
if (i != result.begin())cout << " ";
cout << setfill('0')<<setw(5) << *i;
}
return 0;
}
平平无奇
据说map和set都是红黑树?那我就使劲find了o((⊙﹏⊙))o.