-->
当前位置:首页 > 题库

PROGRAMMING:Polynomial addition

Luz5年前 (2021-05-10)题库436
One day, $$DH $$got two polynomials. Now he wants to know the coefficient of each term after the addition of the two polynomials, but $$DH $$is not good at mathematics, so he intends to ask for help from you.
###Input format:
There are two lines of input. The first line represents the first polynomial, and the second line represents the second polynomial.
The first number of each line is $$n $, which means that the polynomial has a total of $$n $$items, followed by $$n $$to number $$a_ i,b_ I $$, first number $$a_ I $$is the coefficient, and the second number is $$B_ I $$is the index.
The index of each line may appear many times, and the index order is not guaranteed
$$(0<=a_ i,b_ i<=9)$$, $$(1<=n<=10)$$
###Output format:
Output a total of one line, according to the index from large to small, output coefficient, each coefficient is separated by a space (if the coefficient is $$0 $, no output).
Note that there are no spaces at the end of the line
###Input example:
Here is a set of inputs. For example:
```in
4 2 3 3 2 1 1 0 0
3 2 3 3 2 1 1
```
###Output example:
The corresponding output is given here. For example:
```out
4 6 2
```
### tips:
The first polynomial is $$2 * x ^ 3 + 3 * x ^ 2 + 1 * x ^ 1 + 0 * x ^ 0$$
The second polynomial is $$2 * x ^ 3 + 3 * x ^ 2 + 1 * x ^ 1$$
The sum of the two polynomials is $$4 * x ^ 3 + 6 * x ^ 4 + 2 * x ^ 1 + 0 * x ^ 0$$
The topic requires that the output coefficient is not $$0 $, so only $$4-6-2 $$is output, and $$0 $$is not output < br > < br > < br > < br > < br > < br > in the title


answer:If there is no answer, please comment