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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include<bits/stdc++.h>
using namespace std;
const int N = 100100;
long long n,m; string s1[N],s2[N];
map<string, bool> ex; map<long long, string> st;
map<string, bool> e1; map<string, bool> e2;
vector<string> ans;
int main() { cin >> n >>m; for (int i = 0; i < n; ++ i){ cin >> s1[i]; } for (int i = 0; i < m; ++ i){ cin >> s2[i]; } int max_n = max(n, m);
long long idx = 0; long long p1 = 0, p2 = 0; for (int i = 0; i + p1 < n || i + p2 < m; i ++){ while (e1[s1[i + p1]] == 1 ){ p1 ++; if (i + p1 >= n ){ break; } } if (i + p1 < n ){ st[idx ++] = s1[i + p1]; e1[s1[i + p1]] = 1; }
while (e2[s2[i + p2]] == 1 ){ p2 ++; if (i + p2 >= m){ break; } } if (i + p2 < m){ st[idx ++] = s2[i + p2]; e2[s2[i + p2]] = 1; } }
for (long long i = 0; i < idx; i ++){ if (ex[st[i]] != 1){ ans.push_back(st[i]); ex[st[i]] = 1; } } for (long long i = 0; i < ans.size() - 1; i++){ cout << ans[i] << endl; } cout << ans[ans.size() - 1];
}
|