In this partial-judged problem, you are to implement a class polynomial
which supports the following basic operation:
istream
(for instance, cin
is an object of istream
)ostream
(for instance, cout
is an object of ostream
)A polynomial
has two properties: an integer degree and an array coefficients. For the purpose of simplify the constructor and destructor, we use std::array<>
which appeared since C++11 rather than the conventional C-style array. You can use it as is.
Due to it is a bit tricky to overload the operator>>
with istream
, it had been almost done for you and you only need to implement a method to complete the operator.
Check function.h
cautiously before you start.
There are several testcases, each of which contains two lines of polynomials \(A(x), B(x)\) and a black line. For each line of polynomial, it is started by an interger \(d\) indicating the degree of the polynomial, followed by \(d+1\) intergers which are the coeffcients in the descending order.
The degree won't exceed \(10^5\). (It's defined as N in function.h
.)
It's guranteed that the polynomial is valid, i.e., the leading coefficient is not zero.
For 20% of testcases, the coefficients of \(A(x), B(x), A(x)-B(x)\) are positive.
For 50% of testcases, the coefficients of \(A(x), B(x)\) are positive and the coefficient of \(A(x)-B(x)\) are non-negative.
For every two polynomial, the main() would print out \(A(x), B(x), A(x)+B(x), A(x)-B(x)\) and a blank line.
The output format of the polynomial is:
+
" or " -
" without the quotation marks)x^
\(e\) if \(e>1\), else print x
if \(e=1\), otherwise not print any if it is a constant term.The sample output includes many examples.