You are given definitions of multiple polynomials, such as F(x)=+2x^2 +3x +1
and G(x)=+2x +1
, along with several operations to perform on these polynomials, like F(2)+G(3)
, You need to compute the results of these operations.
This problem is a partial judge.
Please implement functions defined in the header file:
Polynomial(int deg, const int *coeffs)
Constructor: Initializes polynomial with degree and coefficient array Polynomial(const Polynomial& other)
Copy constructor: Creates a copy of another polynomial Polynomial operator+(const Polynomial& other) const
Addition operator: Adds two polynomials Polynomial operator-(const Polynomial& other) const
Subtraction operator: Subtracts one polynomial from another Polynomial operator*(const Polynomial& other) const
Multiplication operator: Multiplies two polynomialsPolynomial& operator=(const Polynomial& other)
Assignment operator: Assigns one polynomial to anotherint evaluate(int x) const
Evaluates polynomial at given value x, The result must be taken modulo 109+7. If the result is negative, add 109+7 after taking the modulo to ensure the final answer is non-negative.friend std::ostream& operator<<(std::ostream& os, const Polynomial& poly)
Output stream operator: Prints polynomial to output streamThe first line contains two positive integers n and m, where n is the number of polynomials, and m is the number of operations to perform
The next n lines describe the polynomials. Each line is in one of two formats:
<symbol> = <polynomial>
, which defines the mathematical expression for that polynomial (e.g., "F = 2x^2 + 3x + 1"
).<symbol1> = <symbol2>
, which means the polynomial defined by <symbol1>
is the same as the polynomial defined by <symbol2>.<func1> <op> <func2> <x>
, where:<func1>
and <func2>
are the names of two polynomials.<op>
is an operator, which can be +
, -
, or *
, indicating the operation to perform (addition, subtraction, or multiplication).<x>
is the value of x to substitute into the polynomials<poly> = <ans>
, where:<poly>
is the mathematical expression of the resulting polynomial after performing the operation on <func1>
and <func2>
.<ans>
is the value of the resulting polynomial evaluated at x = x.<ans>
must be taken modulo 109+7. If the result is negative, add 109+7 after taking the modulo to ensure the final answer is non-negative.