infix-type variable suffix time limit: +Ms | Memory Limit:65535KB Difficulty:3
-
-
Describe
-
People's Daily habits are written in the arithmetic expression infix, but for the machine is more "accustomed to" suffix, about the arithmetic expression of the infix and suffix of the general data structure of the book has relevant content to see, here no longer repeat, now your task is to change infix type suffix.
-
-
Input
-
-
The first line enters an integer n, and there are n sets of test data (N<10).
Each set of test data has only one row, is a string of not more than 1000, indicating the infix of the expression, each expression is "=" end. This expression contains only +-*/and parentheses. Where parentheses can be used in a nested set. The data guarantees that no negative numbers appear in the operands entered.
Data guarantee Divisor is not 0
-
-
Output
-
-
each group outputs the corresponding suffix of the group infix, requiring the adjacent operand operators to be separated by a space.
-
-
Sample input
-
-
21.000+2/4= ((1+2) *5+1)/4=
-
-
Sample output
-
-
1.000 2 4/+ = 1 2 + 5 * 1 + 4/=
-
-
Code:
-
#include <stdio.h>int main () {int t,i,top;Char str[1005],ch[1005];scanf ("%d", &t);while (t--){scanf ("%s", str);Top=-1;for (i=0;str[i]!= ' n '; i++){if (str[i]>= ' 0 ' &&str[i]<= ' 9 '){while ((str[i]== '. ') | | (str[i]>= ' 0 ' &&str[i]<= ' 9 ')){printf ("%c", Str[i]);i++;}printf ("");}if (str[i]== ' = ')Breakif (str[i]== ') '){while (top>=0&& (ch[top]!= ')){printf ("%c", Ch[top]);top--;}top--;}else if (str[i]== ' ('){top++;Ch[top]=str[i];}else if (str[i]== ' * ' | | str[i]== '/'){while ((ch[top]== ' * ') | | (ch[top]== '/')){printf ("%c", Ch[top]);top--;}top++;Ch[top]=str[i];}Else{while (top>=0&& (ch[top]!= ')){printf ("%c", Ch[top]);top--;}top++;Ch[top]=str[i];}}while (top>=0){printf ("%c", Ch[top]);top--;}printf ("=\n");}return 0;}
infix-type variable suffix