大大大大大大大模拟
#include<bits/stdc++.h>
using namespace std;
queue<char> A;//存两个人的牌
queue<char> B;
vector<char> v;//存桌上的牌
string a, b;
map<char, int> r;//记录某张牌在哪个位置
int t;
int main() {
cin >> a >> b;
for (int i = 0; i < a.size(); i++)
A.push(a[i]);
for (int i = 0; i < b.size(); i++)
B.push(b[i]);
int cnt = 0;
bool first = true;
while (!A.empty() and !B.empty()) {
if (t >= 100000) {
cout << -1 << endl;
return 0;
}
t++;
if (first) {
char now = A.front();
v.push_back(A.front());
if (r.count(A.front())) {
int index = r[A.front()];
for (int i = cnt; i >= index; i--) {
A.push(v[i]);
r.erase(v[i]);
v.pop_back();
cnt--;
}
cnt++;
A.pop();
continue;
}
r[A.front()] = cnt++;
A.pop();
}
if (A.empty() or B.empty())break;
char now = A.front();
v.push_back(B.front());
if (r.count(B.front())) {
int index = r[B.front()];
for (int i = cnt; i >= index; i--) {
B.push(v[i]);
r.erase(v[i]);
v.pop_back();
cnt--;
}
B.pop();
cnt++;
first = false;
continue;
}
first = true;
r[B.front()] = cnt++;
B.pop();
}
if (A.empty()) {
int k = B.size();
for (int i = 0; i < k; i++)
cout << B.front(), B.pop();
}
else {
int k = A.size();
for (int i = 0; i < k; i++)
cout << A.front(), A.pop();
}
return 0;
}