1 import java.util.Scanner; 2 3 public class Pukepai{ 4 int[] a=new int[1000]; 5 int[] b=new int[1000]; 6 int aleft,aright,bleft,bright; 7 int[] s=new int[100]; 8 int[] t=new int[9]; 9 int top; 10 int flag; 11 12 public static void main(String[] args){ 13 Pukepai px=new Pukepai(); 14 px.go(); 15 } 16 public void go(){ 17 getNum(a); 18 look(a); 19 getNum(b); 20 look(b); 21 aright=5;bright=5; 22 int topp; 23 while((aleft<aright)&&(bleft<bright)){ 24 if(s[top]==0){ 25 s[top]=a[aleft]; 26 t[a[aleft]]=1; 27 aleft++; 28 }else{ 29 if(t[a[aleft]]==1){ 30 for(int j=top;j>=0;j--){ 31 if(s[j]==a[aleft]){ 32 flag=j; 33 break; 34 } 35 } 36 topp=top; 37 for(int j=flag;j<=topp;j++){ 38 aright++; 39 a[aright]=s[j]; 40 t[s[j]]=0; 41 s[j]=0; 42 if(top>0){top--;} 43 if(j==top){ 44 aright++; 45 a[aright]=a[aleft]; 46 aleft++; 47 } 48 } 49 }else{ 50 s[++top]=a[aleft]; 51 t[a[aleft]]=1; 52 aleft++; 53 } 54 } 55 look(s);look(a); 56 if(s[top]==0){ 57 s[top]=b[bleft]; 58 t[b[bleft]]=1; 59 bleft++; 60 }else{ 61 if(t[b[bleft]]==1){ 62 for(int j=top;j>=0;j--){ 63 if(s[j]==b[bleft]){ 64 flag=j; 65 break; 66 } 67 } 68 topp=top; 69 for(int j=flag;j<=topp;j++){ 70 bright++; 71 b[bright]=s[j]; 72 t[s[j]]=0; 73 s[j]=0; 74 if(top>0){top--;} 75 if(j==top){ 76 bright++; 77 b[bright]=b[bleft]; 78 bleft++; 79 } 80 } 81 }else{ 82 s[++top]=b[bleft]; 83 t[b[bleft]]=1; 84 bleft++; 85 } 86 } 87 look(s); 88 } 89 } 90 public int[] getNum(int[] a){ 91 Scanner scanner = new Scanner(System.in); 92 for(int i=0;i<6;i++){ 93 a[i]=scanner.nextInt(); 94 } 95 return a; 96 } 97 public void look(int[] a){ 98 System.out.println(""); 99 for(int i=0;i<9;i++){ 100 System.out.print(a[i]); 101 } 102 } 103 }
时间: 2024-10-11 16:00:58