Removing Parenthesis

Read an expression and remove parenthesis.

Solution in C    PYTHON
#include<stdio.h>
int main() {
    char str[50];
    int i,j,k;
    fgets(str,50,stdin);
    for(i=0;str[i]!='\0';i++){
        if(str[i]=='(' || str[i]==')'){
            for(j=i+1,k=i;str[k]!='\0';j++,k++)
                str[k]=str[j];
            i--;
        }
    }
    puts(str);
}

Input
(A*B)+(C/D)-E
Output
A*B+C/D-E

No comments:

Post a Comment

Total Pageviews