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

ONP Transform the Expression, my code and its logic is Written below please help me to debug it .

$
0
0

include <iostream>

include <stdio.h>

include <cstdlib>

include <string.h>

using namespace std;

int main() { int t; // cin>>t;

char ch[401];

int i=0,j;

scanf("%s",ch);
getchar();
for(i=0;i<strlen(ch);i++)
{
    if(ch[i]>=97&&ch[i]<=122)
    printf("%c",ch[i]);

    if(ch[i]==')')  //  ((a+t)*((b+(a+c))^(c+d)))
    {
        j=i;

        while(ch[j]!='+'||ch[j]!='-'||ch[j]!='*'||ch[j]!='^')
        j--;


        printf("%c",ch[j]);
        ch[j]=32;
    }
}





return 0;

}

Logic :

example : ((a+t)*((b+(a+c))^(c+d)))

check each element of the string and as an alphabet appears , print it, and if ')' appears , go back fetching for operators, and as you find the operator, print it.


Viewing all articles
Browse latest Browse all 40121

Trending Articles



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