22095_EquationSolver

2022-5-16 18:21| 发布者: Hocassian| 查看: 21| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89506106507299-Problem List-采集的数据-后羿采集器.html

Pro.ID

22095

Title

Equation Solver

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22095

AC

0

Submit

1

Ratio

0.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others)
  • 描述

    Write a program that can solve linear equations with one variable.

    输入

    The input will contain a number of equations, each one on a separate line. All equations are strings of less than 100 characters which strictly adhere to the following grammar (given in EBNF):
    Equation   := Expression '=' Expression
    
    Expression := Term { ('+' | '-') Term }
    Term       := Factor { '*' Factor }
    Factor     := Number | 'x' | '(' Expression ')'
    Number     := Digit | Digit Number
    Digit      := '0' | '1' | ... | '9'
    Although the grammar would allow to construct non-linear equations like "x*x=25", we guarantee that all equations occuring in the input file will be linear in x. We further guarantee that all sub-expressions of an equation will be linear in x too. That means, there won't be test cases like x*x-x*x+x=0 which is a linear equation but contains non-linear sub-expressions (x*x).
    Note that all numbers occuring in the input are non-negative integers, while the solution for x is a real number.

    输出

    Description

    Write a program that can solve linear equations with one variable.

    Input
    The input will contain a number of equations, each one on a separate line. All equations are strings of less than 100 characters which strictly adhere to the following grammar (given in EBNF):
    Equation   := Expression '=' Expression
    
    Expression := Term { ('+' | '-') Term }
    Term       := Factor { '*' Factor }
    Factor     := Number | 'x' | '(' Expression ')'
    Number     := Digit | Digit Number
    Digit      := '0' | '1' | ... | '9'
    Although the grammar would allow to construct non-linear equations like "x*x=25", we guarantee that all equations occuring in the input file will be linear in x. We further guarantee that all sub-expressions of an equation will be linear in x too. That means, there won't be test cases like x*x-x*x+x=0 which is a linear equation but contains non-linear sub-expressions (x*x).
    Note that all numbers occuring in the input are non-negative integers, while the solution for x is a real number.
    Output

    For each test case, print a line saying "Equation #i (where i is the number of the test case) and a line with one of the following answers:

    • If the equation has no solution, print "No solution.".

    • If the equation has infinitely many solutions, print "Infinitely many solutions.".

    • If the equation has exactly one solution, print "x = solution" where solution is replaced by the appropriate real number (printed to six decimals).

    Print a blank line after each test case.

    Sample Input

    x+x+x=10
    4*x+2=19
    3*x=3*x+1+2+3
    (42-6*7)*x=2*5-10

    Sample Output
    Equation #1
    x = 3.333333

    Equation #2
    x = 4.250000

    Equation #3
    No solution.

    Equation #4
    Infinitely many solutions.
    Source

    样例输入

    x+x+x=10
    4*x+2=19
    3*x=3*x+1+2+3
    (42-6*7)*x=2*5-10

    样例输出

    Equation #1
    x = 3.333333

    Equation #2
    x = 4.250000

    Equation #3
    No solution.

    Equation #4
    Infinitely many solutions.

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部