P23166 [AtCoder] Alternate World Expression
普及+
题目描述

Problem Description

You are playing a simulation game where you manage a shop in an alternate world. In this world, the way mathematical expressions involving arithmetic operations are written is different from the usual way.

Normally, when writing expressions, arithmetic operations are expressed with operators in the middle, like 1+2+3 or 10/5. However, in this world, arithmetic operations are expressed in a function-call-like format. For example, the corresponding expressions for the previous examples would be +(1,2,3) or /(10,5).

More strictly, expressions in this world are either a sequence of digits or an operator (+, -, *, /) followed by an opening parenthesis (, then several expressions separated by commas ,, and finally a closing parenthesis ). The number of expressions inside the parentheses can be any number greater than or equal to 1 for addition and multiplication (+, *), but must be exactly 2 for subtraction and division (-, /).

For example, 0123, +(10,*(20,30),-(40,50)), and *(5) are all valid expressions. On the other hand, strings like +((1)) or -(5) are not valid expressions.

Given a string $ S $ representing an expression from this alternate world, create a program to convert it into a normal (infix notation) expression. The converted expression must meet the following conditions:

  • The parentheses in the converted expression must appear exactly at the corresponding positions of the original parentheses. For example, +(1,-(2,3)) should be converted to (1+(2-3)), and *(5) should be converted to (5).
  • Numbers appearing in the input, including leading zeros, must be output as they are.
  • No extra spaces should be added. For example, +(1,2) must not be converted to (1 + 2) but rather to (1+2).

For more details on these conditions, refer to the input/output examples.

Input Format

The input is given from the standard input in the following format:

$ S $

Output Format

Output the converted expression in one line.

Sample Input and Output

Sample Input #1

*(*(0,5),+(14,3),-(5,77))

Sample Output #1

((0*5)*(14+3)*(5-77))

Sample Input #2

+(1,+(+(2,3)),+(4,+(5)))

Sample Output #2

(1+((2+3))+(4+(5)))

Sample Input #3

9876

Sample Output #3

9876

Sample Input #4

+(123456789,12345678901234567890,0,00,000,0123456789)

Sample Output #4

(123456789+12345678901234567890+0+00+000+0123456789)

Sample Input #5

*(5)

Sample Output #5

(5)

Notes/Hints

Constraints

  • $1 \leq |S| \leq 10^5$
  • The string $ S $ consists only of operators (+, -, *, /), parentheses ((, )), commas (,), and digits, and is a valid expression in the alternate world.

Sample Explanation 2

Pay close attention to the positions and numbers of parentheses.

Sample Explanation 4

There is no explicit upper limit on the numbers appearing in the expression. Also, note that notations with leading zeros are considered valid, and such numbers must be output as they are.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
*(*(0,5),+(14,3),-(5,77))
样例输出
((0*5)*(14+3)*(5-77))