14528 - Loki doing Math   

Description

Loki need to pursue physics, however he need to undersand basic math first.

In the first lecture, he already messed up with the prefix to infix equation. Can you help him?

Given Math Equation in prefix form, try to figure out the infix equation with the least amount of necessary parenthesis

e.g. given prefix form * - 20 30 50

the infix form will be (20-30)*50

((20-30)*50)is wrong since there is an unnecessary parenthesis

The opreator only consist of +-,  *, and /

 

Same as homework, try to use getline and use strlen if the length is neccesarry

char * equation;
size_t buf = 0;
while(getline(&equation, &buf, stdin) != -1){ 
     // TODO 
}
SINCE THE GETLINE ISN'T RECOGNIZE BY SOME COMPILER, YOU CAN TRY THIS WAY:

#include <stdio.h>

int main(){
    char buffer[100];
    while(fgets(buffer, sizeof(buffer), stdin) != NULL){
        printf("Char %s", buffer);
    }
    return 0;
}


Try to get used to the function above

Input

There will be multiple testcase, each testcase have only 1 line string input

len(string) < 10000

Every number shown in the string are in range [0, 9999]

 

Testcase 1-2: only operator +

Testcase 3-4: operator and -

Testcase 5-6: operator +-,  and *

Testcase 7-8: operator +-,  *,  and /

Output

For each testcase, print the infix equation, ended by a newline character

Sample Input  Download

Sample Output  Download

Tags




Discuss