Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2017. október 29.

October 29, 2017 10:00 AM – October 29, 2017 3:00 PM

Linear Equation

You have been asked to write a program that can solve a simple linear equation.

Input Specification

The first line of the input contains a single integer P (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing one simple linear equation. All equations are strings of less than 200 characters. Each equation will be in the form of ax, followed by a single space, followed by a sign “+”, followed by b, followed by a single space, followed by a sign “=”, followed by a single space, followed by c:

ax + b = c,

where x is the variable (real number), and a, b, c are nonnegative integers.

Output Specification

For each data set, generate three lines of output. The first line contains “Equation n” where n is the number of the data set. The second line contains the following answer:

  • If the equation has no solution, print “No solution.”.
  • If the equation has infinitely many solutions, print “More than one solution.”.
  • If the equation has exactly one solution, print “x = solution”, where solution is replaced by the appropriate real number (printed with six decimals).

The third line is a blank line.

Sample Input

  1. 5
  2. 2x + 3 = 4
  3. 124x + 20 = 160
  4. 123456x + 7 = 2000
  5. 0x + 2 = 3
  6. 0x + 2 = 2
download as text file

Output for Sample Input

  1. Equation 1
  2. x = 0.500000
  3. Equation 2
  4. x = 1.129032
  5. Equation 3
  6. x = 0.016143
  7. Equation 4
  8. No solution.
  9. Equation 5
  10. More than one solution.
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019