题解
2023-03-31 21:15:25
发布于:上海
46阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
string s1, s2;
deque<char>q1, q2, q3;
bool flag = true;
bool flag1 = true;
void Input_deque() {
int len1 = s1.length(), len2 = s2.length();
for(int i = 0; i < len1; i++) q1.push_back(s1[i]);
for(int i = 0; i < len2; i++) q2.push_back(s2[i]);
}
void Output_deque(deque<char>q) {
int siz = q.size();
while(!q.empty()) {
cout << q.front();
q.pop_front();
}
}
int main() {
ios::sync_with_stdio(false);
cin>>s1>>s2;
Input_deque();
while(1) {
if(flag == true) {
char a = q1.front(); q1.pop_front();
q3.push_back(a);
if(count(q3.begin(), q3.end(), a) >= 2) {
q3.pop_back(); q1.push_back(a);
while(1) {
char c = q3.back();
q3.pop_back();
q1.push_back(c);
if(c == a) break;
}
flag = true; continue;
}
}
flag = false;
if(q1.empty()) { flag1=false; break;}
else if(q2.empty()) break;
if(flag == false) {
char b = q2.front(); q2.pop_front();
q3.push_back(b);
if(count(q3.begin(), q3.end(), b) >= 2) {
q3.pop_back(); q2.push_back(b);
while(1) {
char c = q3.back();
q3.pop_back();
q2.push_back(c);
if(c == b) break;
}
flag = false; continue;
}
}
flag = true;
if(q1.empty()) { flag1=false; break;}
else if(q2.empty()) break;
}
if(flag1 == false)
Output_deque(q2);
else Output_deque(q1);
return 0; }
这里空空如也
有帮助,赞一个