本文最后更新于 2181 天前,其中的信息可能已经有所发展或是发生改变。
#include<iostream>
#include<queue>
#include <typeinfo>
using namespace std;
int main(){
queue<char> x,y;
char ch1[20],ch2[20],z[40];
cin>>ch1>>ch2;
int i=0,flag=0;
while(ch1[i]!='\0'){
x.push(ch1[i]);
i++;
}
i=0;
while(ch2[i]!='\0'){
y.push(ch2[i]);
i++;
}
int flag3=1,flag4=0;
while(true){
flag4++;
if(flag3==1){
int flag1=0,flag2=0;
for(int j=flag;j>0;j--){
if(z[j]==x.front()){
flag1=1;
char temp=z[j];
x.pop();
x.push(temp);
for(int k=flag;k>0;k--){
flag--;
if(z[k]!='b'){
if(z[k]==temp){
x.push(z[k]);
z[k]='b';
break;
}
else{
x.push(z[k]);
z[k]='b';
}
}
}
}
flag3=1;
}
if(flag1==0){
flag++;
z[flag]=x.front();
x.pop();
flag3=0;
}
}
else{
int flag1=0,flag2=0;
for(int j=flag;j>0;j--){
if(z[j]==y.front()){
flag2=1;
char temp=z[j];
y.pop();
y.push(temp);
for(int k=flag;k>0;k--){
flag--;
if(z[k]!='b'){
if(z[k]==temp){
y.push(z[k]);
z[k]='b';
break;
}
else{
y.push(z[k]);
z[k]='b';
}
}
}
}
flag3=0;
}
if(flag2==0){
flag++;
z[flag]=y.front();
y.pop();
flag3=1;
}
}
if(x.empty()||y.empty()){
break;
}
}
if(x.empty()&&!y.empty()){
while(!y.empty()){
cout<<y.front();
y.pop();
}
return 0;
}
if(!x.empty()&&y.empty()){
while(!x.empty()){
cout<<x.front();
x.pop();
}
return 0;
}
if(x.empty()&&y.empty()){
cout<<-1;
return 0;
}
}