-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVA-10152.cpp
51 lines (48 loc) · 1.15 KB
/
UVA-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
51
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
int main(){
int k;
cin >> k;
for(int i=0; i<k; ++i){
int n;
cin >> n;
vector<string> vs(n);
vector<int> v(n);
map<int, string> mItoS;
map<string, int> mStoI;
string s;
getline(cin, s);
for(int j=0; j<n; ++j){
getline(cin, s);
vs[n-j-1]=s;
}
for(int j=0; j<n; ++j){
getline(cin, s);
mItoS[n-j-1]=s;
mStoI[s]=n-j-1;
}
for(int j=0; j<n; ++j){
v[j]=mStoI[vs[j]];
}
//start from the bottom, for every name thats not in order move the lowest to the top
vector<int> toSwap;
int mini=0;
for(int j=0; j<n; ++j){
if(v[j]!=mini) toSwap.push_back(v[j]);
else mini++;
}
sort(toSwap.begin(), toSwap.end());
for(int j=0; j<(int) toSwap.size(); j++){
cout << mItoS[toSwap[j]] << endl;
}
cout << endl;
}
return 0;
}