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
#include <stdio.h>
int main(){
char buffer[100];
while(fgets(buffer, sizeof(buffer), stdin) != NULL){
printf("Char %s", buffer);
}
return 0;
}
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 /
For each testcase, print the infix equation, ended by a newline character