We would like to design a program that helps us in performing polynomial calculations. We want our calculator to support the following features:
Each input line contains a polynomial or an operation.
A polynomial is in a human-readable expression, e.g., x^7 +2*x^3 -x +10. The coefficients are integers, and the exponents are non-negative integers. A polynomial is in a descending order of exponents.
An operation is one of the four character, +, -, *, and /.
The formulas to calculate are in a "postfix" representation, which is directly evaluated from left to right. For example, let X, Y, and Z are polynomials.
We can assume the following for simplicity:
The values of the coefficients and exponents are not excessive large; 32-bit int variables should be able to perform the calculation.
When a division is performed, the dividend is a multiple of the divisor. The results are quotient with integer coefficients and non-negative integer exponents without any remainder.
The output first repeats the input.
The last line of the output contains a equation mark, =, followed by the calculation result.
Please note the conventions of expressing a polynomial. Let us take x^5 -3*x^2 +x +7 for example. The following variants of the polynomial are not good:
+x^5 -3*x^2 +x + 7 (we should omit the leading plus mark)
+1*x^5 -3*x^2 +x + 7 (we should omit the leading +1* coefficient)
x^5 + -3*x^2 +x + 7 (we should omit this plus mark for breavity)
x^5 +0*x^4 -3*x^2 +x + 7 (we should omit any zero term)
x^5 -3*x^2 +1*x + 7 (we should omit any 1* coefficient)
x^5 -3*x^2 +x^1 + 7 (we should omit an ^1 exponent)
x^5 -3*x^2 +x + 7x^0 (we should omit x^0)