System of Linear Equations
Time limit1sMemory limit128 MB
Parse two linear equations and report each unknown as a reduced fraction, or as don't know when it is not uniquely determined.
- Level
Medium4 of 10
- Topics
- Math, Implementation, String
- Solved
- No attempts yet
Problem
You are given a system of two linear equations in the unknowns and . Write a program that solves the system.
Input
The first line contains the number of test cases .
Each test case consists of two equations, one per line. Different test cases are separated by a blank line.
In each equation, two or more terms are joined by the operators +, -, and =. Each term is either an integer or a variable ( or ); a variable may be preceded by a minus sign and/or a coefficient. The = sign appears exactly once per equation. Every operator is surrounded by spaces, and a single term contains no spaces.
Output
For each test case, print the value of and then the value of , one per line, as a reduced fraction. If a value is an integer, print just the integer with no denominator.
If the value of a variable is not uniquely determined — that is, the system has no solution, or that variable may take more than one value — print don't know in its place. The two variables are judged independently, so it is possible for one variable to have a fixed value while the other is don't know.
Print a blank line between the outputs of consecutive test cases.