You are given two Strings, first and second. Each of these strings contains a simple linear equation with variables x and y. Your task is to determine whether this pair of equations has a unique solution, and if so, to compute it.
Each of the equations is of the form "A*X + B*Y = C". The spaces must appear exactly as in this example, i.e., there is exactly one space both before and after the signs "+" and "=", and there are no other spaces. The coefficients A, B, and C are integers. If a coefficient is non-negative, the equation contains just the number, without the unary plus sign. If a coefficient is negative, it is always enclosed in parentheses, and it contains the unary minus sign. No coefficient will contain unnecessary leading zeroes.
If the pair of equations has a unique solution, return the solution formatted as a String of the form "X=A/B Y=C/D", where A, B, C, and D are integers such that both fractions A/B and C/D are reduced, and the numbers B and D are positive. The numbers should be encoded in the same way as the coefficients of the equations -- i.e., negative numbers must be enclosed in parentheses.
If the pair of equations has more than one solution, return the String "MULTIPLE SOLUTIONS". If the pair of equations has no solutions,
return the String "NO SOLUTIONS".
|