CodeChef submission 827941 (JAVA) plaintext list. Status: AC, problem ONP, contest . By saadhussain (saadhussain), 2012-02-04 14:54:49.
import java.io.*; { { return "STACK IS FULL !!"; } } { { return "STACK IS EMPTY !!"; } } class Stack { int top; char elements[]; final static int SIZE=500; { top=-1; elements=new char[SIZE]; } public void push(char data) throws StackFullException { if(top==(SIZE-1)) { throw new StackFullException(); } else { elements[++top]=data; } } public char pop() throws StackEmptyException { if(top!=-1) return elements[top--]; else throw new StackEmptyException(); } public void display() { for(int i=top;i>=0;i--) { } } } class rpn { { for(i=0;i<t;i++) { data[i]=input.readLine(); data[i]+=')'; fin[i]=""; } try { stack.push('('); //stack.display(); } { } for(i=0;i<t;i++) { for(j=0;j<data[i].length();j++) { char c=data[i].charAt(j),tmp; if(c>='a'&&c<='z') { fin[i]+=c; } if(c==')') { try { tmp=stack.pop(); while(tmp!='(') { fin[i]+=tmp; tmp=stack.pop(); } } { //System.out.println(e.toString()); } } if(c=='+') { try { tmp=stack.pop(); while(tmp=='-'||tmp=='*'||tmp=='/'||tmp=='^'||tmp=='+') { fin[i]+=tmp; tmp=stack.pop(); } stack.push(tmp); stack.push(c); } { //System.out.println(e.toString()); } } if(c=='-') { try { tmp=stack.pop(); while(tmp=='+'||tmp=='*'||tmp=='/'||tmp=='^'||tmp=='-') { fin[i]+=tmp; tmp=stack.pop(); } stack.push(tmp); stack.push(c); } { //System.out.println(e.toString()); } } if(c=='*') { try { tmp=stack.pop(); while(tmp=='*'||tmp=='/'||tmp=='^') { fin[i]+=tmp; tmp=stack.pop(); } stack.push(tmp); stack.push(c); } { //System.out.println(e.toString()); } } if(c=='/') { try { tmp=stack.pop(); while(tmp=='*'||tmp=='/'||tmp=='^') { fin[i]+=tmp; tmp=stack.pop(); } stack.push(tmp); stack.push(c); } { //System.out.println(e.toString()); } } if(c=='^') { try { tmp=stack.pop(); while(tmp=='^') { fin[i]+=tmp; tmp=stack.pop(); } stack.push(tmp); stack.push(c); } { //System.out.println(e.toString()); } } if(c=='(') { try { stack.push(c); } { //System.out.println(e.toString()); } } } //stack.display(); } for(i=0;i<t;i++) { } } }
Comments

