
If there is no solution for the equation, return "No solution.”
If there is only one solution for the equation, return that solution for ‘x.’
If there are infinite solutions for the equation, return "Infinite solutions.”
‘x’ may or may not have coefficients associated with it.
‘+’, ‘-’, and ‘x’ can occur any number of times in the equation.
The first line contains a single integer ‘T’ representing the number of test cases.
The next ‘T’ lines contain a string ‘S’ representing the equation given to Nobita.
For each test case, print the value of ‘x’, and if the solution doesn’t exist, then print “No solution,” and if there are infinite solutions, then print “Infinite solutions”.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
3 <= |S| <= 10^7
-100 <= y <= 100
Time limit: 1 sec
Each constant and each variable have a corresponding sign to them ‘+’ or ‘-’. So divide the string into two partitions; all that comes before “=” is LHS and after “=” is treated as RHS. Then exclusively use the property of shifting from LHS to RHS or vice versa to solve the equation.
The steps are as follows: