﻿PAT(B) 1065. 单身狗(25)-Ocrosoft

# PAT(B) 1065. 单身狗(25)

“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人，以便给予特殊关爱。

```3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333
```

```5
10000 23333 44444 55555 88888
```
```#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define strend string::npos
#define ms(a) memset(a,0,sizeof(a))
#define rep(a,v,b) for(int a=v;a<b;a++)
#define repe(a,v,b) for(int a=v;a<=b;a++)
#define pre(a,v,b) for(int a=v;a>b;a--)
#define pree(a,v,b) for(int a=v;a>=b;a--)
#define lowbit(x) x&-x
typedef long long LL;
const LL LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const int MAXN = 27 + 10;
const int MOD = 1000000007;
int gcd(int a, int b)
{
if (!b)return a;
return gcd(b, a%b);
}
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
/*(◕‿‿◕) 签订契约,成为马猴烧酒吧 (◕‿‿◕)*/
/*(◕‿‿◕)(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
using namespace std;
int main()
{
int n, m;
cin >> n;
map<string, string> md;
while (n--)
{
string a, b;
cin >> a >> b;
md[a] = b;
md[b] = a;
}
cin >> m;
map<string, bool> mp;
while (m--)
{
string s;
cin >> s;
mp[s] = 1;
}
map<string, bool>::iterator it = mp.begin();
bool flag = 0;
vector<string> v;
for (; it != mp.end(); it++)
{
if (md.count(it->first))
{
if (mp.count(md[it->first])) {}
else v.push_back(it->first);
}
else v.push_back(it->first);
}
printf("%d\n", v.size());
if (v.size() == 0)return 0;
for (int i = 0; i < v.size(); i++)
if (i == 0)cout << v[i];
else cout << " " << v[i];
printf("\n");
return 0;
}
```