시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 28 3 2 40.000%

문제

방정식 f(x) = 0을 푸는 프로그램을 작성하시오. f(x)는 후위표기법으로 쓰여져 있으며, 숫자와 연산자 +, -, *, /, 그리고 변수 x로 이루어져 있다. x는 방정식에서 최대 한 번 등장한다.

예를 들어, 방정식 (4x + 2)/2 = 0에 대한 f(x)는 아래와 같이 쓰여져 있다.

4 X * 2 + 2 /

방정식 f(x) = 0의 해는 x = -1/2 이다.

입력

첫재 줄에 방정식 f(x)가 주어진다. 변수 x는 X로 주어지며, 연산자 +,-,*,/ 와 숫자 0-9로 이루어져 있다. X는 최대 한 번 등장한다. 최대 30개의 토큰이 주어진다.

0으로 나누지 않고 해를 구할 수 있는 경우만 입력으로 주어진다.

출력

f(x) = 0의 해가 하나인 경우에는 X = p/q를 출력한다. 이 때, p와 q는 서로소이어야 하고, q는 양수이어야 한다.

f(x) = 0의 해가 없는 경우에는 NONE을 출력한다.

f(x) = 0의 해가 한 개 보다 많은 경우에는 MULTIPLE을 출력한다.

예제 입력 1

4 X * 2 + 2 /

예제 출력 1

X = -1/2
W3sicHJvYmxlbV9pZCI6IjM1ODYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjMjlcdWM4MTVcdWMyZGQiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmMyOVx1YzgxNVx1YzJkZCBmKHgpID0gMFx1Yzc0NCBcdWQ0NzhcdWIyOTQgXHVkNTA0XHViODVjXHVhZGY4XHViN2E4XHVjNzQ0IFx1Yzc5MVx1YzEzMVx1ZDU1OFx1YzJkY1x1YzYyNC4gZih4KVx1YjI5NCBcdWQ2YzRcdWM3MDRcdWQ0NWNcdWFlMzBcdWJjOTVcdWM3M2NcdWI4NWMgXHVjNGYwXHVjNWVjXHVjODM4IFx1Yzc4OFx1YzczY1x1YmE3MCwgXHVjMjJiXHVjNzkwXHVjNjQwIFx1YzVmMFx1YzBiMFx1Yzc5MCArLCA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