×

# Wrong answer in ONP-Transform the expression

 0 My code inspite of generating all the test cases is showing wrong answer #include #include #include typedef struct stack { char a[400]; int top; } stack; stack s; void push(char *,int); int pop(); int main(void) { char x[400]; int len,i,n,y; scanf("%d",&n); while(n>0) { scanf("%s",x); len=strlen(x); for(i=0;i=97&&x[i]<=122) printf("%c",x[i]); else if(x[i]=='/'||x[i]=='*'||x[i]=='+'||x[i]=='-'||x[i]=='^') { push(x,i); } else if(x[i]=='(') continue; else { y=pop(); printf("%c",y); } } while (s.top !=0) { y = pop(); printf("%c", y) ; } n--; } return 0; } void push(char *x,int i) { s.top++; s.a[s.top]=x[i]; } int pop() { int temp; temp=s.a[s.top]; s.top--; return temp; }  asked 24 Mar '15, 17:32 1★artist 23●2●14 accept rate: 0%

 0 After each test case u need to move to a new line which ur code is not doing put a printf("\n") for each test case answered 24 Mar '15, 17:40 3★sharru05 559●1●7●23 accept rate: 14%
 0 You need to print each output ( expressions in RPN form ) at a new line and it will be accepted. In your code, add a new line after exhausting the stack contents.  while (s.top !=0) { y = pop(); printf("%c", y) ; } printf("\n"); // new line after the stack elements are popped n--;  Check your accepted code with the above modification here. answered 24 Mar '15, 17:40 1.1k●3●13 accept rate: 36% Yes now its working Thanks.) (24 Mar '15, 17:52) artist1★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,490
×1,409
×173

question asked: 24 Mar '15, 17:32

question was seen: 1,084 times

last updated: 24 Mar '15, 17:52