시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 58 5 4 16.667%

문제

방정식 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는 양수이어야 한다. 해가 0인 경우에는 X = 0/1을 출력한다.

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

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

예제 입력 1

4 X * 2 + 2 /

예제 출력 1

X = -1/2

예제 입력 2

1 2 / 2 4 / - X *

예제 출력 2

MULTIPLE

예제 입력 3

1 1 X 2 + / /

예제 출력 3

NONE
W3sicHJvYmxlbV9pZCI6IjM1ODYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjMjlcdWM4MTVcdWMyZGQiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmMyOVx1YzgxNVx1YzJkZCBmKHgpID0gMFx1Yzc0NCBcdWQ0NzhcdWIyOTQgXHVkNTA0XHViODVjXHVhZGY4XHViN2E4XHVjNzQ0IFx1Yzc5MVx1YzEzMVx1ZDU1OFx1YzJkY1x1YzYyNC4gZih4KVx1YjI5NCBcdWQ2YzRcdWM3MDRcdWQ0NWNcdWFlMzBcdWJjOTVcdWM3M2NcdWI4NWMgXHVjNGYwXHV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