CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Transform the Expression

Transform the Expression

Problem code: ONP

  • Submit
  • All Submissions

All submissions for this problem are available.

Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 − 4 + 5" would be written "3 4 − 5 +" first subtract 4 from 3, then add 5 to that.

Transform the algebraic expression with brackets into RPN form.

You can assume that for the test cases below only single letters will be used, brackets [] will not be used and each expression has only one RPN form (no expressions like a*b*c)

Input

The first line contains t, the number of test cases (less then 100).

Followed by t lines, containing an expression to be translated to RPN form, where the length of the expression is less then 400.

Output

The expressions in RPN form, one per line.

Example

Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))

Output:
abc*+
ab+zx+*
at+bac++cd+^*

Author: admin
Date Added: 1-12-2008
Time Limit: 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

skydiploma @ 26 May 2009 07:52 PM

I think that this problem should give out a list of 'symbols' like ,-,*, etc.
As it didnt mention that any non alphabet is to be considered as a symbol.

sanjay_ankur @ 14 Jun 2009 03:50 AM

a simple infix to postfix transformation????

diamondback @ 19 Jul 2009 09:11 AM

Does anyone know if the ^ operator is for Exponent or binary XOr? They have different precedence.

admin 2 @ 20 Jul 2009 06:06 PM

It's the power operation.

anshu_ranjan @ 23 Jul 2009 07:52 AM

Is it needed to take care of precedence of the operators?? It is not mentioned in the problem.

admin 2 @ 23 Jul 2009 06:37 PM

From what I can see, the operators are completely paranthesized.

swirve @ 7 Aug 2009 02:39 PM

if you assume that everything is parenthesized, and that everything not a lower case letter or a parenthesis is an operator, then you will solve the problem.

very funny but it compiles

sharath @ 19 Aug 2009 12:10 AM
very funny but it compiles and executes fine on my linux c++ and g++ compiler, and here i get a SIGSEGV error?? any ideas why this happening?

A SIGSEGV is usually caused

admin @ 19 Aug 2009 02:28 AM

A SIGSEGV is usually caused if you try to access memory that is not available to your program. It is a segfault. Check the FAQ for more information.

Do we have to consider the

aseem_pandey @ 23 Aug 2009 02:52 PM
Do we have to consider the inputs like : (a+((b+c)*(e+f))-(i+j)). because it transforms to (m+(n*o)- p)? Also please tell me that a expression like (a+(b+(c))) is valid ???? Summarily, should the no. of closing parenthesis be equal to no operators in the complete expression as in the sample input???

please read the last line

aseem_pandey @ 23 Aug 2009 02:55 PM
please read the last line like this- "Summarily, should the no. of closing parenthesis be equal to no. of operators in the complete expression as in the sample input?"

All inputs are fully

admin @ 23 Aug 2009 06:03 PM

All inputs are fully parantetized. I see nothing wrong with the inputs you have given. They perfectly fit the input definition provided in the statement and as such are valid.

Is there any special case in

himanshu mishra @ 28 Aug 2009 04:10 PM

Is there any special case in this too? Because for sample inputs I am getting correct output, but when I submit, it says wrong answer. I have considered operators +,-,/,*,^ .

The code is tested against

admin @ 28 Aug 2009 04:33 PM

The code is tested against test cases other than the sample ones.

Is an expression like (a+b+c)

sumitdas083 @ 16 Sep 2009 12:13 AM

Is an expression like (a+b+c) valid?

 

are there any exceptional

muneer @ 23 Sep 2009 11:29 AM
are there any exceptional cases in the programme

No, the test cases are in

admin @ 23 Sep 2009 02:17 PM

No, the test cases are in accordance with the format specified.

this is one of the problems

jcomeau_ictx @ 22 Oct 2009 06:27 AM

this is one of the problems where using psyco with Python makes sense, though it's still way slower than a C program with the algorithm I used.

I dont know why I am still

srinivasan__ @ 25 Oct 2009 10:57 PM

I dont know why I am still getting "SIGSEGV" error while I try to submit for ONP problem. Can anybody help me out?

SIGSEGV indicates a segfault.

admin @ 26 Oct 2009 01:00 PM

SIGSEGV indicates a segfault. Check the FAQ and www.codechef.com/wiki for more details. You might want to check for areas in the code where you might be accessing memory you are not supposed to or which doesn't exist.

are there more operators

sanjayk @ 27 Oct 2009 11:00 AM

are there more operators apart from +,-,/,*,^ ?

No.

triplem @ 27 Oct 2009 11:27 AM

No.

Just pointing out a small

Alexander Supertramp @ 14 Nov 2009 04:55 AM

Just pointing out a small spelling error...

In the 'Input' section of the problem description, it should be 'less than', not 'less then'.

anybody has input data for

mosiesrm @ 9 Dec 2009 10:15 PM

anybody has input data for testing this problem?

I think the problem statement

a2ms @ 8 Feb 2010 06:24 PM

I think the problem statement needs to be a little more specific, like if we have to consider upper and lower case to the single letters and which operations are supported. Is it just the ones showed as example (+ - *) or the complete basic operations (+ - * /) or does it even include more symbols like exponentiation (^) or left (-)

of course i'm blind and

a2ms @ 8 Feb 2010 07:19 PM

of course i'm blind and didn't saw that the exponentiation is actually included...

do v have to put input like

sahilkalra @ 17 Feb 2010 04:46 PM

do v have to put input like abc or the numerical value and get the answer?

For u who working with

jod4ta @ 1 Mar 2010 02:02 AM

For u who working with python, my esperrience below might help.

I always get "runtime error" for this task, today i submit, and still get "runtime error" and then i submit my second code for the purpose to get at least "wrong answer" :

for i in range(t_input):
infix=raw_input()
print 'wtf'

I am shock when i get "correct answer" with time 0.78 s. Then i submit again my wrong submission and finally get "wrong answer". Then i go to my account and look into my "RECENT ACTIVITY FOR THIS USER" and get check mark for first submission and get cross mark for the other.

I know i'm newbie but this is too weird for me. Can someone explain it to me?

i cannot use getche() to get

saurabh167 @ 9 Apr 2010 08:14 PM

i cannot use getche() to get my input... ????

In the Sample problems we

darkmonk @ 29 Apr 2010 02:37 PM

In the Sample problems we don't need to check the operator precedence.. are there other cases in which it is required.. as m getting wrong answer but have tried many combinations according to the sample cases given.

That is already mentioned in

triplem @ 29 Apr 2010 04:33 PM

That is already mentioned in earlier comments.

its saying wrong answer pls

ni8mare @ 11 May 2010 09:13 PM

its saying wrong answer pls help me

still wrong answer pls help

ni8mare @ 11 May 2010 09:20 PM

still wrong answer pls help

Does "Time Limit Exceeded"

Sand33Prakash @ 16 May 2010 02:31 AM

Does "Time Limit Exceeded" mean that the solution was correct but only the time limit was not met?

FAQ

triplem @ 16 May 2010 04:15 AM

FAQ

@Stephen Merriman :

Sand33Prakash @ 16 May 2010 04:22 PM

@Stephen Merriman : Thanks

With respect to the post from "Aseem Kumar - 23rd Aug,2009 14:52:48.", in reply to which "Admin - 23rd Aug,2009 18:03:51" says that expression of the form (m+(n*o)- p) is totally valid expression. This expression further transforms to (m+x-p). I wonder as to how this can be correct as it is stated in the question that "(no expressions like a*b*c)". Should we handle these kind of expressions as well?

@Stephen Merriman :

Sand33Prakash @ 16 May 2010 04:22 PM

@Stephen Merriman : Thanks

With respect to the post from "Aseem Kumar - 23rd Aug,2009 14:52:48.", in reply to which "Admin - 23rd Aug,2009 18:03:51" says that expression of the form (m+(n*o)- p) is totally valid expression. This expression further transforms to (m+x-p). I wonder as to how this can be correct as it is stated in the question that "(no expressions like a*b*c)". Should we handle these kind of expressions as well?

Does the "SUCCESSFUL

Sand33Prakash @ 16 May 2010 08:01 PM

Does the "SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:" contain only the 1st correct submission only is it? I submitted my solution which took 0.45 Sec and later I improved my algorithm (offcourse seeing the implementation in other language) and reduced the runtime to 0.19. I do not see an entry for this.

Can anyone help me out with

tlgylmz @ 19 May 2010 07:55 PM

Can anyone help me out with my solution. It says :"wrong answer". But I could not point out the problem on my own.

here it goes

tlgylmz @ 19 May 2010 07:56 PM

here it goes : http://www.codechef.com/viewsolution/243885

Are there any exceptional

ronzii @ 13 Jun 2010 10:21 AM

Are there any exceptional test cases?

I hve solved problems in my

rafaftahsin @ 19 Jul 2010 10:59 AM

I hve solved problems in my computer using Turbo C++ IDE...it gives correct solutions...but when i submit it...it sayz error...!!! I can't fix the problem...!!!

You haven't made any

triplem @ 19 Jul 2010 01:21 PM

You haven't made any submissions to this problem. Did you mean Small Factorials instead? If so, you should read the FAQ. Also, your most recent submission doesn't work for any large inputs - try some.

my program is working

divyark @ 27 Jul 2010 12:20 PM

my program is working perfectly fine for single infix expression.... i am using gets function to collect the infix expression...... but to collect the number of infix expressions ie the first input i cant use scanf bec gets doesnt work wen used after scanf plz guide me............

printf("enter the number of expressions to convert:n);

scanf("%d",&y);??

k=1;

while(k<=y)

{

 printf(" enter the infix expression:n");

gets(infix);????

 

Why not just continue to use

triplem @ 27 Jul 2010 01:41 PM

Why not just continue to use scanf then? Much simpler than trying to use gets.

(By the way, your output must be exactly what the problem statement tells you to print out.. it doesn't start with the word 'enter'..)

i will remove the print f s

divyark @ 27 Jul 2010 01:58 PM

i will remove the print f s while submitting in code chef...... in case i want 2 use scanf while taking in the infix expression i should give only fixed length infix expressions or i should be taking an input of size of the infix exp every time.........

like

for(i=0;i<=4;i++)

scanf("%c",&infix[i]); // for giving (2+3) this is fine... but for giving ((2*3)-(1*2)) i hav 2 change the i<=4 to i<=14..... i cant do this 4 each input?......

Respected admin, I have 2

Illusion03 @ 27 Jul 2010 02:00 PM

Respected admin, I have 2 Question 2 ask?

1) From the above given comments, I m not sure whether to check for Precedence of Operators or not b'cause there are already present inside parenthesis?

2)which operators should i check for ... i have taken all the other ASCII characters as operators xcept (97-122,a-z) and (41 , 42 i.e (, ) )....or should i check for only basic operations like +,-,*,^,/ ?

PLease Help as soon as possible .. I have submitted my code 6 times and all time wrong answer ! U can also have a look at my code !

Thanks ! :)

Respected Admin, Sir I have

Illusion03 @ 28 Jul 2010 07:18 PM

Respected Admin,

Sir I have completed this Problem but before that i got about 6 wrong answers and they were only due to i used link-list for making stacks, but this time i used array for making stack and voila it was a correct submission...Can u just clear my doubt why i was getting wrong answer when i was using link-list,Although it was giving correct answer for every possible INFIX notation in DEVC++.

Thanks ! :)

can anyone plz tell me what's

credo @ 2 Aug 2010 11:42 AM

can anyone plz tell me what's wrong wid this code? i'm getting the right output on ma gcc compiler!

thanx :)

#include<stdio.h>
#include<string.h>
#define MAX 20
char stack[MAX];
int top=-1;
char pop();
void push(char item);
int prcd(char symbol)
{
switch(symbol)
{
case '+':
case '-':return 2;
case '*':
case '/':return 4;
case '^':
case '$':return 6;
case '(':
case ')':
case '#':return 1;
}
}
int isoperator(char symbol)
{
switch(symbol)
{
case '+':
case '-':
case '*':
case '/':
case '^':
case '$':
case '(':
case ')':return 1;
default:return 0;
}
}
void convertip(char infix[],char postfix[]){
int i,symbol,j=0;
char test[MAX];
stack[++top]='#';
for(i=0;i<strlen(infix);i++){
symbol=infix[i];
if(isoperator(symbol)==0){
postfix[j]=symbol;
j++;
}
else{
if(symbol=='(')push(symbol);
else if(symbol==')'){
while(stack[top]!='('){
postfix[j]=pop();
j++;
}
pop();//pop out (.
}
else{
if(prcd(symbol)>prcd(stack[top]))
push(symbol);
else{
while(prcd(symbol)<=prcd(stack[top])){
postfix[j]=pop();
j++;
}
push(symbol);
}//end of else.
}//end of else.
}//end of else.
}//end of for.
while(stack[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='';//null terminate string.
}

void push(char item){
top++;
stack[top]=item;
}
char pop(){
char a;
a=stack[top];
top--;
return a;
}

int main(){
unsigned int inputs,i;
char infix[400],postfix[400];
scanf("%d",&inputs);
for(i=0;i<inputs;i++){
scanf("%s",infix);
convertip(infix,postfix);
printf("%s",postfix);
}
return 0;
}


hi I've submitted the

shwetanka_19 @ 9 Aug 2010 03:04 AM

hi

I've submitted the solution many times but everytime I'm getting a wrong answer. I've tried different ways to solve but nothing seems working. Can I find out what I'm missing. Thanks

#include<stdio.h>#include<std

padmaja_39 @ 20 Aug 2010 07:24 PM

#include<stdio.h>
#include<stdlib.h>
#define stacksize 100
#include<string.h>
int top=-1;
char st[stacksize];
void push(char a);
char pop();
char peek();
void push(char a)
{
   
     if(top==(stacksize-1))
     printf("stack full");
     else
     {
         ++top;
         //printf("hi%d",top);
         st[top]=a;
         
         }}
char pop()
{
    if(top==-1)
    return 0;
    else
    {
        //top = top-1;
        return st[top--];
        }}        
char peek()
{
    if(top==-1)
    return 0;
    else
    return st[top];
    }
char p[8][2]={{'(',-1},{'+',1},{'-',1},{'*',2},{'/',2},{'%',2},{'^',3},{')',4}};
int main()
{
     
int ch,i,j,m,k=0,n,test;
char a[400];char pd[100][400];char expr[400];char a1[400];

//printf("enter expression");
scanf("%d",&test);
//printf("%s",a);

//for(i=0;a[i]!='';i++)
//printf("%c",a[i]);
if(test < 100)
{
for(m=0;m<test;m++)
{
                   scanf("%s",a1);
                   strcpy(pd[m],a1);
                   }}
for(m=0;m<test;m++)
{
strcpy(a,pd[m]);
for( i=0;a[i]!='';i++)
{
    //printf("%c",a[i]);
     if(a[i] == '(')
     {
             //printf("one");
             push(a[i]);
             }
             else if(a[i]>='a' && a[i]<='z')
             {
              //printf("two");
              expr[k++] = a[i];
              }
                else if(a[i] == ')')
                {
                   //printf("three");
                     char item;
                item=pop();
               
                                while(item!='(')
                                {
                                expr[k++] = item;
                                item = pop();
                                }
                                }
                               else
                               {
                                               //printf("four");
                                    int precedence;
                                    for( j=0;j<8;j++)
                                    {
                                            if(p[j][0] == a[i])
                                               precedence = p[j][1];
                                              
                                               }
                                               //printf("%d",precedence);
                                               int precedence1;
                                               char rj = peek();
                                        for( j=0;j<8;j++)
                                            {
                                            if(p[j][0] == rj)
                                               precedence1 = p[j][1];
                                               } 
                                            //printf("%d",precedence1);
                                              if(precedence1 >= precedence)
                                               {
                                                            char rt = pop();
                                                            expr[k++] = rt;
                                                            }
                                                            else
                                                            push(a[i]);
                                                            }
                                                            }
                                                           
                 n=k;
                 for(i=0;i<n;i++)
                 printf("%c",expr[i]);
                 printf("n");
                 k=0;                
                 }
                                  
                                                    

return 0;
         }

my code is not getting

padmaja_39 @ 20 Aug 2010 07:25 PM

my code is not getting accepted.It shows run time error.How can i resolve it?

http://en.wikipedia.org/wiki/

default1130 @ 22 Sep 2010 08:05 PM
http://en.wikipedia.org/wiki/Shunting-yard_algorithm

i m getting runtime error for

sarathsat @ 22 Sep 2010 09:20 PM
i m getting runtime error for my code. But it s working perfectly in my pc.. plz help me in resolving it.. #include #include void compute(char a[]); char b[100][400]; int main() { int n=0; int i,end; scanf("%d",&n); for( i=0;i=97&& (int)b[i][h] <=122) { operand[j]=b[i][h];j++; } else { operator[k]=b[i][h]; if(operator[k]==')') { k--; do { operand[j++]=operator[k--]; }while(operator[k]!='('); k--; } k++; } h++; } for(h=0;h

#include #include void

sarathsat @ 22 Sep 2010 09:21 PM
#include #include void compute(char a[]); char b[100][400]; int main() { int n=0; int i,end; scanf("%d",&n); for( i=0;i=97&& (int)b[i][h] <=122) { operand[j]=b[i][h];j++; } else { operator[k]=b[i][h]; if(operator[k]==')') { k--; do { operand[j++]=operator[k--]; }while(operator[k]!='('); k--; } k++; } h++; } for(h=0;h

@admin: On my system I'm

codu2009 @ 16 Oct 2010 06:08 PM

@admin:

On my system I'm getting correct answer for many test cases I've created and also for the sample input given in the problem. May I know what is going wrong. My solution is : http://www.codechef.com/viewsolution/360251

Thank you.

how can i challenge my

tarun_kumar @ 23 Oct 2010 09:55 PM

how can i challenge my friends on facebook.

when i click on the link i cant see my friends list

I just found out that not

Anirudh Kishan @ 11 Nov 2010 07:00 PM

I just found out that not returning 0 in main will produce a Runtime Error!!!!

 

Is it a convention or necessity to return 0? Logically, if a program runs successfully shouldn't it return 1?

It is a necessity to return 0

triplem @ 12 Nov 2010 01:34 AM

It is a necessity to return 0 (as mentioned in the FAQ). Returning anything else is exactly what signals a runtime error.

Thanks!

Anirudh Kishan @ 12 Nov 2010 06:52 PM

Thanks!

@admin: y cannt i submit

neoahead @ 30 Nov 2010 11:58 AM

@admin: y cannt i submit solution to this problem???? tryin it from morning.... it says cannt submit solution itseems :(

SUMBODY reply .. zzZZzz..

neoahead @ 30 Nov 2010 12:04 PM

SUMBODY reply .. zzZZzz.. need to move on to next problem..

Can u tell why i am getting

mygaurav @ 22 Dec 2010 12:17 AM

Can u tell why i am getting wrong answer: i hv run the program for the test cases given and others

my code is

http://www.codechef.com/viewsolution/404848

i got the answer : but i wish

mygaurav @ 22 Dec 2010 01:07 PM

i got the answer : but i wish to ask that why i was getting wrong answer when i used gets() instead of scanf() in getting infix string as input

fflush(stdin) is undefined

triplem @ 22 Dec 2010 01:56 PM

fflush(stdin) is undefined and should never be used. See http://c-faq.com/stdio/gets_flush2.html

#include<stdio.h>#include<str

vishaldonderia @ 25 Dec 2010 12:52 PM

#include<stdio.h>
#include<string.h>
int stack[100];int top =0;
int push(int f)
{top++;stack[top] = f;}
int pop()
{top--;return(stack[top+1]);}
int pre1(int d){
switch(d){
case 43:
case 45:
return 1;
break;
case 42:
case 47:
return 3 ;
break;
case  94:
return 6;
break;
case 40:
return 9;
break;
case 41:
return 0;
break;
default:
return 7;
break;}}
int pre2(int d){
switch(d){
case 43:
case 45:
return 2;
break;
case 42:
case 47:
return 4;
break;
case  94:
return 5;
break;
case 40:
return 0;
break;
default:
return 8;
break;}}
int main()
{stack[top] = '(';
char a[400];
int l,n,i,j,u,k;
scanf("%d",&n);
for(k=1;k<=n;k++){
scanf("%s",&a);
l = strlen(a);
a[l]=')';
for(i=0;i<l;i++){
j =a[i];
if(pre1(j)>pre2(stack[top])){push(j);}
else{ while(pre1(j)<pre2(stack[top]))
{
printf("%c",pop());}
if(pre1(j) == pre2(stack[top]))
u = pop();
else
push(j);}}
printf("n");}
}
error shown in this code is RUNTIME ERROR ,and run time error  is due "The most common reasons are using too much memory or dividing by zero"..but my memory is 1.6 M and i did'nt divide by zero..can any one tell me whats the error in my code ..please.

hey can somebody plzz tell me

codeur @ 27 Dec 2010 01:18 AM

hey can somebody plzz tell me why m i getting a wrong ans! I have tried almost every possible test case , even (!a) and (a) as well. but stil I cant find d mistake. http://www.codechef.com/viewsolution/407705 is my code

hey can somebody plzz tell me

codeur @ 27 Dec 2010 08:49 PM

hey can somebody plzz tell me why m i getting a wrong ans! I have tried almost every possible test case , even (!a) and (a) as well. but stil I cant find d mistake. http://www.codechef.com/viewsolution/407705 is my code

yeeh solved!!!

junan_chakma @ 10 Jan 2011 10:22 PM

yeeh solved!!!

#include<stdio.h>char

singh_637 @ 9 Feb 2011 12:18 AM

#include<stdio.h>



char stack[200];
int Top=-1;
char infix[400],postfix[400];
void PUSH(char x)
{
if(Top==200-1)
printf("n Over flow in stack");
else
stack[++Top]=x;
}


char POP()
{
if(Top==-1)
{
return ('');
}
else
return(stack[Top--]);
}

int precedence(char d)
{
int value=0;
switch(d)
{
case '^':value=5;
break;
case '*':
case '/':value=4;
break;
case '-':
case '+':value=3;
break;
}
return value;
}

int main()
{
char c;
int p1=0,p2=0,i=0,j=0,testcase,z=0;

printf("n Enter the number of test cases=");
scanf("%d",&testcase);
while(testcase--)
{
Top=-1;
p1=0;p2=0;i=0;j=0;
printf(" n Enter the infix statement=");
scanf("%s",&infix);
while(infix[i]!='')
{
if( infix[i]>='a' && infix[i]<='z')
{
postfix[j]=infix[i];
j++;
}
else if(infix[i]=='^'||infix[i]=='*' || infix[i]=='/' ||infix[i]=='+' || infix[i]=='-')
{
p1=precedence(infix[i]);
Y : p2=precedence(stack[Top]);
if(p1<=p2)
{
c=POP();
postfix[j]=c;
j++;
goto Y;

}
else
PUSH(infix[i]);
}
else if( infix[i]=='(')
PUSH(infix[i]);
else if(infix[i]==')')
{
while((c=POP())!='(')
{
postfix[j]=c;
j++;
}
}
i++;
}
postfix[++j]='';
printf(" n %s",postfix);
z++;
}

return 1;
}

 

Why am i getting runtime error?

Try returning 0 , return 1

alanexe @ 12 Feb 2011 04:44 PM

Try returning 0 , return 1 means that something went wrong

Im getting runtime error with

alanexe @ 12 Feb 2011 04:45 PM

Im getting runtime error with this soultion 
http://www.codechef.com/viewsolution/455706

It runs ok on my pc.

Anyone have some advice ?

http://www.codechef.com/views

rahiakil @ 25 Feb 2011 02:02 PM

http://www.codechef.com/viewsolution/468651

 

I am getting this as wrogn answer. Any help

nice problem.

devendra @ 25 Feb 2011 04:21 PM

nice problem.

@Admin, why my program always

harish_8080 @ 18 Apr 2011 03:08 PM

@Admin, why my program always takes 1.6M, no matter how much memory I use.

Even if I submit that Life, Universe and everything problem which needs only one variable in the program and simple loop and if statement. Still I get 1.6M ?

I skimmed through the

eipie @ 31 May 2011 10:18 PM
I skimmed through the comments like I usually do. The only really useful question is if (m+(n*o)- p) is valid. And the answer is NO it isn't. it should be written as (m-p+(n*o)) = (m-p)+(n*o). (m+(n*o)-p) isn't well formed.

@admin Tested for about 100

malaykeshav @ 8 Jun 2011 04:22 AM
@admin Tested for about 100 cases,but still giving the wrong answer.Need to know which option is going wrong ?!?! http://ideone.com/eU9D7

Hi cOdeRS, you Don't Need to

bodmas @ 26 Jun 2011 12:42 PM
Hi cOdeRS, you Don't Need to consideR operATor precedEnCe to sOlVe thIS problEm!

@admin, Can you please post

chaitanyav @ 14 Aug 2011 03:29 PM
@admin, Can you please post why my program is getting WA?.

my last post gave me run time

vedp1 @ 19 Aug 2011 10:13 PM
my last post gave me run time error can sum1 specify the reason....asmin..pls check...

my last post gave me run time

vedp1 @ 19 Aug 2011 10:14 PM
my last post gave me run time error can sum1 specify the reason....admin..pls check...

@vedp1: the length of the

vijay91 @ 19 Aug 2011 11:24 PM
@vedp1: the length of the expression is less then 400 and you are using array of 60 characters... read more here http://www.codechef.com/wiki/faq#Why_do_I_get_a_Runtime_exception

should we also define

rahul09it64 @ 8 Sep 2011 03:18 PM
should we also define exceptional cases like: (a+b*(c-d), a+b(c*d), etc as errors???

plz supply tutorial about

rokon1cuet_51 @ 27 Sep 2011 04:54 PM
plz supply tutorial about this problem.

for all those who are trying

prabal03 @ 26 Jan 2012 05:31 PM
for all those who are trying to solve in c/c++ and getting 'wrong answer'. the problem may be that you all are not terminating the string by NULL... this may help

import java.io.*; class

prateekraj1988 @ 13 Feb 2012 06:09 PM
import java.io.*; class RPN1 { static char arr[]; static void readd()throws Exception { int l,k=0; String s; File f=new File("Input1.txt"); FileReader fr=new FileReader(f); BufferedReader br=new BufferedReader(fr); FileReader fr1=new FileReader(f); BufferedReader br1=new BufferedReader(fr1); l=Integer.parseInt(br.readLine()); if(l<100) { br1.readLine(); while((s=br.readLine())!=null) { k++; } if(l==k) { while((s=br1.readLine())!=null && s.toCharArray().length<400) { compute(s); } } } fr.close(); fr1.close(); } public static void main(String args[])throws Exception { try { readd(); } catch(Exception e) { e.printStackTrace(); } } static void compute(String s) { int i=0,j,p=1,k,t=0,m=0,n=0; arr=s.toCharArray(); while(arr[0]=='(' && arr[arr.length-1]==')') { for(j=n;j='a' && arr[j+1]<='z')) { k=j+1; m=k; while(arr[m]>='a' && arr[m]<='z') { //t++; m++; } while(arr[k]!=')') { while(arr[m]<'a' || arr[m]>'z') { if(arr[m]=='(') { t=1; n=m; break; } m++; } if(t==1) { p=0; break; } p=1; k++; } if(p!=0) { transform(arr,m-1,k-1,j); n=0; break; } else { t=0; break; } } } //i++; } for(int l=0;l

this code is working fine on

prateekraj1988 @ 13 Feb 2012 06:10 PM
this code is working fine on my system but do not understand why it is giving run time error while submission

If the expression written "3

makandriaco @ 15 May 2012 03:25 AM
If the expression written "3 − 4 + 5" would be written "3 4 − 5 +" , shouldn't the expression (a+(b*c)) be written "bc*a+"? instead of abc*+

you skipped

husky @ 22 May 2012 02:38 AM
you skipped semicolons... (a+(b*c)) == abc*+ b*c+a == bc*a+

add some more testcases.

madhupadikar @ 26 May 2012 04:47 PM
add some more testcases.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com