Ограничения: время – 1s/2s, память – 64MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод
Послать решение Blockly Посылки Темы Где Обсудить (0)
Given the equation on the variables `x` and `y`, represent it in the standard form `"ax"` + `"by"\ =\ c`, where numbers `a,\ b,\ c` haven't common divisors, and coefficients `a` and `b` are nonnegative.
The first line of input contains `N`, the number of test cases. Each test case is one equation on a separate line with the length less than 100. An equation consists of two or more terms separated by addition, subtraction, or equality operators. A term is an integer, or a variable name (`x` or `y`) optionally preceded by a minus sign or an integer coefficient. There is exactly one equality operator. All operators are surrounded by spaces, and there are no spaces within terms. All integers are in range from –100 to 100. For each case, print one line with the equation in standard form. If both coefficients `a` and `b` equal 0, print "wrong equation" instead. If `a` or `b` equals 0, skip a term with 0. Don't print the coefficient 1 in front of variable either.
Sample input
8
2x + 3y = 4x – 3x
5 = x + y + 3
3y + 2x = 0
10x = 15y
x + y = x + y
2x = -3
-2y = 3
1 = 2
Sample output
x + 3y = 0
x + y = 2
2x + 3y = 0
2x - 3y = 0
wrong equation
2x = -3
2y = -3
wrong equation