PAT 甲级 刷题日记|A 1121 Damn Single (
2021-09-02 本文已影响0人
九除以三还是三哦
思路
给N对夫妻编号,再给M个派对里的参与人的编号,输出单身的人的编号(包括夫妻没全部到场的也算单身)
代码
#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> couple;
int n, p;
vector<int> las;
int flag[100002];
vector<int> ans;
int main() {
cin>>n;
for (int i = 0; i < 2 * n; i++) {
int num;
cin>>num;
couple[num] = i / 2 + 1;
}
cin>>p;
for (int i = 0; i < p; i++) {
int peo;
cin>>peo;
if (couple.find(peo) == couple.end()) {
ans.push_back(peo);
} else {
las.push_back(peo);
int n = couple[peo];
flag[n]++;
}
}
int t = las.size();
for (int i = 0; i < t; i++) {
int now = couple[las[i]];
if (flag[now] == 1)
ans.push_back(las[i]);
}
sort(ans.begin(), ans.end());
int s = ans.size();
cout<<s<<endl;
for (int i = 0; i < s; i++) {
printf("%05d", ans[i]);
if (i != s - 1) cout<<" ";
else cout<<endl;
}
}