#P1022. Solving a Linear Equation in One Variable
Solving a Linear Equation in One Variable
Solving a Linear Equation in One Variable
Given a linear equation in one variable, your task is to compute its unique real solution. The equation entered on the calculator consists only of integers, lowercase letters, and the symbols +
, -
, and =
. (Note that the symbol -
can represent either subtraction or a negative sign.) There are no parentheses or division symbols. The letter (which may be any lowercase letter) represents the unknown variable.
You may assume that the input equation is valid and always has a unique real solution. The equation can be represented in the general form \[ Ax + B = Cx + D, \] so that its solution is given by \[ x = \frac{D - B}{A - C}. \]
inputFormat
The input consists of a single line containing a valid one-variable linear equation. The equation will only include integers, lowercase letters, and the symbols +
, -
, and =
.
outputFormat
Output a single number which is the solution of the equation. The answer should be printed as a floating-point number.
sample
4+3x=8
1.3333333333333333