11409 - DS QUIZ2(1)   

Description

Given several polynomials each represented by a linked list, write a program that sums these polynomials.

You need to implement the link list for this quiz, otherwise you’ll get 0 points.

#include <vector> is not allowed.

Input

Each line contains a polynomial.

The input may contain multiple polynomials (at least two) and the length of each input line does not exceed 20000 characters.

The format of the polynomial is the following.

Each input line can be divided into multiple pairs of numbers.

In each pair, the first number represents the coefficient, and the second represents power. Every coefficient is 32-bit signed integer, and the power is 32-bit signed integer.

For example:

30 7 25 3 4 2 3 1 -5 0 -1 -1

can be viewed as 6 different pairs
30 7 25 3 4 2 3 1 -5 0 -1 -1

representing the following polynomial

30x^7 + 25x^3 + 4x^2 + 3x^1 - 5x^0 – 1x^-1

Output

Please output the sum of polynomials and follow the power down format.
Please note that if the coefficient is 0, we do not need to output the coefficient (i.e., 0) and its corresponding power.
If every coefficient of the output polynomial is 0, then output: 0 0

Sample Input  Download

Sample Output  Download

Tags




Discuss