시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 35 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
W3sicHJvYmxlbV9pZCI6IjM1ODYiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWJjMjlcdWM4MTVcdWMyZGQiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmMyOVx1YzgxNVx1YzJkZCBmKHgpID0gMFx1Yzc0NCBcdWQ0NzhcdWIyOTQgXHVkNTA0XHViODVjXHVhZGY4XHViN2E4XHVjNzQ0IFx1Yzc5MVx1YzEzMVx1ZDU1OFx1YzJkY1x1YzYyNC4gZih4KVx1YjI5NCBcdWQ2YzRcdWM3MDRcdWQ0NWNcdWFlMzBcdWJjOTVcdWM3M2NcdWI4NWMgXHVjNGYwXHVjNWVjXHVjODM4IFx1Yzc4OFx1YzczY1x1YmE3MCwgXHVjMjJiXHVjNzkwXHVjNjQwIFx1YzVmMFx1YzBiMFx1Yzc5MCArLCAt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