Depressed C small plus (a)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.