This problem: is to simulate the stack, determine the probability of the stack order.
Basically everyone's approach is to directly simulate the stack of stacks into the stack and order with the 0,1 sequence to represent, I temporarily did not think of any good ideas.
ImportJava.util.*;ImportJava.io.*; Public classmain{ Public Static voidMain (string[] arg) {Scanner Scan=NewScanner (NewBufferedinputstream (system.in)); int[] Outflag =New int[18];//there are up to 9 trains, 1 indicates that 0 means Char[] Stack =New Char[20]; while(Scan.hasnextint ()) {intn =Scan.nextint (); Char[] put; Char[] Pop; Put=Scan.next (). ToCharArray (); Pop=Scan.next (). ToCharArray (); inttop =-1; intIn=0,out=0,flag=0; while(out!=n&&in!=n+1){ if(Top!=-1&&stack[top] = =Pop[out]) {Top--; out++; Outflag[flag+ +] = 1; Continue; } if(in==N) { Break; } Top++; Stack[top]= put[in++]; Outflag[flag+ +] = 0; } if(flag==2*N) {System.out.println ("Yes."); for(inti = 0; i!= Flag; i + +){ if(outflag[i]==0) {System.out.println ("In"); Continue; } System.out.println ("Out"); } }Else{System.out.println ("No."); } System.out.println ("FINISH"); } scan.close (); }}
hdoj-acm1022 (JAVA)