depressed C small plus (a)
time limit: ms | Memory limit:65535 KB
Difficulty: 3
-
-
Describe
-
we are familiar with expressions such as a+b,a+b* (c+d) and so on are infix expressions. Infix expression is (for binocular operator) operator in the middle of two operands:num1 operand num2. Similarly, a suffix expression is the operator after two operands:num1 num2 operand. ACM team's "C small plus" is depressed how to convert an infix expression to a suffix expression, now you design a program to help C Small add infix expression to the suffix expression. To simplify the problem, the operands are all single digits and the operators are only +-*/ and parentheses.
-
-
Input
-
-
The first line, input T, indicates that there is a T set of test data (T<10).
Each set of test data has only one row, which is a string of not more than 1000 in length, representing the expression. 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. And the input data does not appear to be mismatched.
-
-
Output
-
-
each set of outputs is separated by an output conversion suffix expression.
-
-
Sample input
-
-
21+2 (1+2) *3+4*5
-
-
Sample output
-
-
12+12+3*45*+
-
-
Code
-
#include <stdio.h> #include <string.h> #define MAX 1000int main (void) {int n,i,t,s;Char A[max],ch[max];scanf ("%d", &n);while (n--){S=-1;t=0;Char Str[max];scanf ("%s", str);for (I=0;i<strlen (str); i++){if (str[i]>= ' 0 ' &&str[i]<= ' 9 '){Ch[t++]=str[i];}else if (str[i]== ' ('){A[++s]=str[i];}else if (str[i]== ') '){while (s>=0&&a[s]!= ' ('){ch[t++]=a[s--];}s--;}else if (str[i]== ' + ' | | str[i]== '-'){while (s>=0&&a[s]!= ' ('){ch[t++]=a[s--];}A[++s]=str[i];}Else{while (a[s]== ' * ' | | a[s]== '/'){ch[t++]=a[s--];}A[++s]=str[i];}}while (s>=0){ch[t++]=a[s--];}ch[t]= ' + ';printf ("%s\n", ch);}return 0;}
-
-
Depressed C small plus (a)