Logo
(追記) (追記ここまで)

6968번 - Lottery 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB41201240.000%

문제

You have just won the lottery. All that separates you from your multi-million dollar prize is your correct answer to the following skill-testing question:

1234ドル + 4567 \times 11$

In your twenty seconds you see your fortune slipping away because you don't know whether the answer is

$(1234 + 4567) \times 11 = 63,811円$

or

1234ドル + (4567 \times 11) = 51,471円$

Finally you guess 63811, but that answer is incorrect. Your math teacher set the question and expected you to remember that multiplication is done before addition. The correct answer is 51471.

Your job is to write a program to insert parentheses into lottery questions such as the above so as to make clear the order of operations.

입력

The input to your program consists of a line containing an integer, $n,ドル followed by $n$ lines of input. Each of the $n$ lines contains an expression consisting of integers, and the operators +, -, and X denoting addition, subtraction, and multiplication respectively. Adjacent integers are separated by one operator. There is a single space to the left and to the right of each operator and no input line contains more than 80 characters.

출력

Your output should consist of the same $n$ lines, with a blank line between them, with parentheses inserted in the $n$ lines so as to indicate the order of operations. Multiplication should be done first, from left to right, and addition and subtraction should then be done from left to right. Spaces surrounding operators should be preserved.

제한

예제 입력 1

3
10 + 20 X 30
1 + 2 + 3 - 4
123 + 456 X 789 - 876

예제 출력 1

10 + (20 X 30)
((1 + 2) + 3) - 4
(123 + (456 X 789)) - 876

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 1998 > CCC 1998 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /