-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10152.cpp
50 lines (43 loc) · 1.15 KB
/
10152.cpp
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
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(void)
{
int T, n, but, top, move[200], len;
string origin[200], target[200];
map<string, int> table;
scanf("%d\n", &T);
while (T--) {
table.clear();
scanf("%d\n", &n);
for (int i = n - 1; i > -1; --i)
getline(cin, origin[i]);
for (int i = n - 1; i > -1; --i) {
getline(cin, target[i]);
table[target[i]] = i;
}
but = 0;
top = n - 1;
len = 0;
for (int i = 0; i < n; ++i)
if (table[origin[i]] == but) {
but++;
}
else if (table[origin[i]] > but) {
top = table[origin[i]];
move[len++] = table[origin[i]];
}
else if (table[origin[i]] > top) {
move[len++] = table[origin[i]];
}
sort(move, move + len);
for (int i = 0; i < len; ++i)
printf("%s\n", target[move[i]].c_str());
printf("\n");
}
return 0;
}