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

Wrong answer in ONP-Transform the expression

$
0
0

My code inspite of generating all the test cases is showing wrong answer

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

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<len;i++)
    {
      if((x[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;
   }

Viewing all articles
Browse latest Browse all 39796

Trending Articles



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