-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1065.cpp
More file actions
51 lines (43 loc) · 838 Bytes
/
1065.cpp
File metadata and controls
51 lines (43 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
map<int, int> tem;//两个数据分别对应着伴侣的编号
map<int, int> peo;//关键字为伴侣,值为1代表参加了这次聚会
int n, m;
vector<int> s;//单身狗
cin >> n;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
tem[a] = b;//a的伴侣是b,b的伴侣是a
tem[b] = a;
}
cin >> m;
for (int i = 0; i < m; i++)
{
int c;
cin >> c;
peo[c]++;//代表c参加了这次聚会
}
for (auto i = peo.begin(); i != peo.end(); i++)//循环遍历
{
if (!tem[i->first])//没有伴侣
s.push_back(i->first);
else if(!peo[tem[i->first]])//有伴侣但是没有来
s.push_back(i->first);
}
sort(s.begin(), s.end());
cout << s.size() << endl;
for (int i = 0; i < s.size(); i++)
{
if (i)
cout << " ";
printf("%05d", s[i]);
}
return 0;
}