// 运行超时?
//
#include "stdafx.h"
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
unsigned n;
cin >> n;
map<string, string> data_couple;
for (unsigned i = 0; i < n; ++i)
{
string t1, t2;
cin >> t1 >> t2;
data_couple[t1] = t2;
data_couple[t2] = t1;
}
unsigned m;
cin >> m;
vector<string> data_attend;
for (unsigned i = 0; i < m; ++i)
{
string tmp;
cin >> tmp;
data_attend.push_back(tmp);
}
vector<string> data_sigle;
for (auto &r : data_attend)
{
if (data_couple.find(r) == data_couple.end())
data_sigle.push_back(r);
else
{
auto tmp = data_couple[r];
if (find(data_attend.begin(), data_attend.end(), tmp) == data_attend.end())
data_sigle.push_back(r);
}
}
sort(data_sigle.begin(), data_sigle.end());
cout << data_sigle.size() << endl;
for (size_t i = 0; i < data_sigle.size(); i++)
{
cout << data_sigle[i];
if (i != (data_sigle.size() - 1))
cout << " ";
}
system("pause");
return 0;
}
```
网友评论