infix-type variable suffix

Source: Internet
Author: User

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

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.