解题思路:
注意事项:
测试数据中没有不能结束的情况
参考代码:import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class P1879 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
Queue A = new LinkedList();
Queue B = new LinkedList();
Stack pk = new Stack();
String a=in.next(),b=in.next();
for(int i=0;i
A.offer(a.charAt(i));
for(int j=0;j
B.offer(b.charAt(j));
while(!A.isEmpty() && !B.isEmpty()) {
char c = A.poll();
while(pk.contains(c)) {
A.offer(c);
int t = pk.size() - pk.indexOf(c);
while(t-->0)
A.offer(pk.pop());
c=A.poll();
}
pk.push(c);
if(A.isEmpty()) break;
c = B.poll();
while(pk.contains(c)) {
B.offer(c);
int t = pk.size() - pk.indexOf(c);
while(t-->0)
B.offer(pk.pop());
c=B.poll();
}
pk.push(c);
}
String regex = "[ ,\\[\\]]";
if(A.isEmpty())
System.out.println(B.toString().replaceAll(regex, ""));
else
System.out.println(A.toString().replaceAll(regex, ""));
}
in.close();
}
}