Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Transform the Expression- ONP

$
0
0

I have been coding this code ONP and its giving me the correct answer on my compiler but a wrong answer here. Please someone help me to find the error in my code.

include<stdio.h>

int POP(char stack[400],int top) { top--; if( (stack[top+1]!='(') && (stack[top+1]!=')') ) printf("%c",stack[top+1]); return top; }

int PUSH(char stack[400],int top,char op) { if(top==-1) { top++; stack[top]=op; return top; }

      else
      {
             if(op==')')
             {
             while(stack[top]!='(' )
             top=POP(stack,top);
             if(stack[top]=='(')
             top=POP(stack,top);
             }
             else
             {
               top++;
               stack[top]=op;
             }
                return top;
      }

 }

int main() { short int t; char ch,string[400],S[400]; int TOP=-1,i;

scanf("%d",&t);
fflush(stdin);

while(t--)    
{
    gets(string);
    fflush(stdin);

    for(i=0;string[i]!='\0';i++)
    {
        ch=string[i];
        if( ((ch>='a') && (ch<='z'))||((ch>='A') &&(ch<='Z')) )
        printf("%c",ch);
        else
        TOP=PUSH(S,TOP,ch);
    }
    while(TOP!=-1)
     TOP=POP(S,TOP);
     printf("\n");
}

return 0;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>