2146 - DS_2020_QUIZ2_Stake&Queue Scoreboard

Time

2020/10/28 18:30:00 2020/10/28 20:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12940 DS_2020_QUIZ2_Stack&Queue

12940 - DS_2020_QUIZ2_Stack&Queue   

Description

In this quiz, you are asked to implement Stack and certain arithmetic operations (addition, subtraction, multiplication, division and exponent) to evaluate elementary arithmetic expressions.

Functions:

Implement Stack that transforms the expressions from infix to postfix and evaluates the expressions.

Notes on exponents:

If the expression form is: 3^2^2, it is equivalent to 3^(2^2). The postfix of it is thus 322^^ . As another example: 5^4^3^2 = 5^(4^(3^2)), which has its postfix as 5432^^^.

Test Case:

        The first three test cases include only +-*/.

Notice:

       STL is not allowed in this homework. (string is allowed)

You can use pow(a,b) (which means a^b) function in #include<math.h> to evaluate exponent operation in expression.

 

Input

1. N lines of commands where N<=100. Every line is an independent expression.

2. The number of operators (+, -, *, /, ^) in the expression is smaller than 20; The number of operands is smaller than 20.

3. The expression does not contain any non-divisible condition.

Eg: 8/3 does not appear in the expression.

4. All operands in the expressions are integers within [0,9].

5. The result of the expression (including the first line and any intermediate result of the calculation) is an integer in the range of -2147483648 to 2147483647 (32-bit int).

Output

For each line of the input, three lines of output are generated.
i) Print out the current expression and a new line character. ii) Then, print its postfix and a new line character.
iii) Finally, the evaluation result of the expression.

After the last output, doesn't need to shift to new line. 

Sample Input  Download

Sample Output  Download

Tags




Discuss