21916_LazyMathInstructor

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

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

Pro.ID

21916

Title

Lazy Math Instructor

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    A math instructor is too lazy to grade a question in the exam papers in which students are supposed to produce a complicated formula for the question asked. Students may write correct answers in different forms which makes grading very hard. So, the instructor needs help from computer programmers and you can help.

    You are to write a program to read different formulas and determine whether or not they are arithmetically equivalent.

    输入

    The first line of the input contains an integer N ( 1 ≤ N ≤ 20 ) that is the number of test cases. Following the first line, there are two lines for each test case. A test case consists of two arithmetic expressions, each on a separate line with at most 80 characters. There is no blank line in the input. An expression contains one or more of the following:

    • Single letter variables (case insensitive).

    • Single digit numbers.

    • Matched left and right parentheses.

    • Binary operators +, - and * which are used for addition, subtraction and multiplication respectively.

    • Arbitrary number of blank or tab characters between above tokens.

    Note: Expressions are syntactically correct and evaluated from left to right with equal precedence (priority) for all operators. The coefficients and exponents of the variables are guaranteed to fit in 16-bit integers.

    输出

    Description

    A math instructor is too lazy to grade a question in the exam papers in which students are supposed to produce a complicated formula for the question asked. Students may write correct answers in different forms which makes grading very hard. So, the instructor needs help from computer programmers and you can help.

    You are to write a program to read different formulas and determine whether or not they are arithmetically equivalent.

    Input

    The first line of the input contains an integer N ( 1 ≤ N ≤ 20 ) that is the number of test cases. Following the first line, there are two lines for each test case. A test case consists of two arithmetic expressions, each on a separate line with at most 80 characters. There is no blank line in the input. An expression contains one or more of the following:

    • Single letter variables (case insensitive).

    • Single digit numbers.

    • Matched left and right parentheses.

    • Binary operators +, - and * which are used for addition, subtraction and multiplication respectively.

    • Arbitrary number of blank or tab characters between above tokens.

    Note: Expressions are syntactically correct and evaluated from left to right with equal precedence (priority) for all operators. The coefficients and exponents of the variables are guaranteed to fit in 16-bit integers.

    Output

    Your program must produce one line for each test case. If input expressions for each test data are arithmetically equivalent, "YES", otherwise "NO" must be printed as the output of the program. Output should be all in upper-case characters.

    Sample Input

    3
    (a+b-c)*2
    (a+a)+(b*2)-(3*c)+c
    a*2-(a+c)+((a+c+e)*2)
    3*a+c+(2*e)
    (a-b)*(a-b)
    (a*a)-(2*a*b)-(b*b)

    Sample Output

    YES
    YES
    NO

    Source

    样例输入

    3
    (a+b-c)*2
    (a+a)+(b*2)-(3*c)+c
    a*2-(a+c)+((a+c+e)*2)
    3*a+c+(2*e)
    (a-b)*(a-b)
    (a*a)-(2*a*b)-(b*b)

    样例输出

    YES
    YES
    NO

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部