1 public class trangleProblem { 2 3 static int res=1; 4 int codePart=1; 5 int n=100; 6 Stack<Param> stack=new Stack<Param>(); 7 public static void main(String[] args) { 8 trangleProblem tb=new trangleProblem(); 9 while(tb.solve()==false) 10 ; 11 } 12 13 public boolean solve() 14 { 15 16 17 switch(codePart) 18 { 19 case 1:stack.push(new Param(n, 6)); 20 codePart=2; 21 break; 22 case 2: 23 if(stack.peek().nn==1) 24 codePart=5; 25 else 26 codePart=3; 27 break; 28 case 3: stack.push(new Param(stack.peek().nn-1, 4)); 29 codePart=2; 30 break; 31 case 4:res+=stack.peek().nn; 32 codePart=5; 33 break; 34 case 5: codePart=stack.peek().returnAddress; 35 stack.pop(); 36 break; 37 case 6: 38 return true; 39 40 41 } 42 return false; 43 } 44 45 } 46 class Param 47 { 48 int nn; 49 int returnAddress; 50 Param(int nn,int returnAddress) 51 { 52 this.nn=nn; 53 this.returnAddress=returnAddress; 54 } 55 }
时间: 2024-10-26 02:03:36