A DP Problem
Time limit1sMemory limit128 MB
Parse each linear equation without parentheses, solve for x, and report the floored solution or whether it is impossible or an identity.
- Level
Easy3 of 10
- Topics
- String, Implementation, Math
- Solved
- No attempts yet
Problem
In this problem you must solve a very simple linear equation that has no parentheses and a single variable . An example of such an equation is:
2x-4+5x+300=98x
A general equation contains a = character with one expression on each side. Each expression is one or more terms combined by the + or - operator. Unary + or - operators are not allowed. Each term is either a single integer, an integer followed by the lower-case letter x, or the single character x (which is equivalent to 1x).
Write a program that finds the value of satisfying the equation. Note that the equation may have no solution or infinitely many solutions; your program must detect these cases as well.
Input
The first number () is the number of test cases, followed by lines, each containing one equation. Each line is at most 255 characters long. The equations contain no blank characters and the variable is always the lower-case letter x. The coefficients are integers in the range to inclusive.
Output
For each test case, print one line containing the solution of the equation. If is the solution, the output line must contain (the floor of , i.e., the largest integer less than or equal to ). Print IMPOSSIBLE if the equation has no solution, or IDENTITY if it has infinitely many solutions. The output is case-sensitive.