在programming challenges上没有ac,只在UVA上ac了。不过看了看别人的思路,至少思路上是没问题的。
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <assert.h>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <functional>
#include <string.h>
#include <stdio.h>
#include <numeric>
#include <float.h>
using namespace std;
/*
4.6.7
*/
int main() {
int TC = 0; cin >> TC;
for (int tc = 1; tc <= TC; tc++) {
int num = 0; cin >> num; cin.get();
vector<string> source, objective;
for (int i = 0; i < num; i++) {
string s; getline(cin, s);
source.push_back(s);
}
for (int i = 0; i < num; i++) {
string s; getline(cin, s);
objective.push_back(s);
}
vector<string> removed;
int sourceIndex = num - 1;
for (int i = num-1; i >= 0; i--) {
while (sourceIndex >= 0) {
if (source[sourceIndex] == objective[i]) {
sourceIndex--;
break;
}
else {
removed.push_back(source[sourceIndex]);
}
sourceIndex--;
}
if (sourceIndex < 0) break;
}
for (int i = num - 1; i >= 0; i--) {
for (int j = 0; j < removed.size(); j++) {
if (objective[i] == removed[j]) {
cout << removed[j] << endl;
break;
}
}
}
cout << endl;
}
return 0;
}