HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN112 Homeworks 2013-2015 > problem:


14-Spr2-20. 50442 - Polynomial Addition

CEN112 Homeworks 2013-2015

Start: Dec.15.2013 at 12:00:00 PM
Finish: Dec.15.2013 at 05:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 50345 - Orders
• 50758 - National Elections - Revisited
• 50754 - Team Standings
• 12-Spr1-40. 50327 - Parallel Lines
• 13-Fall2-20. 50395 - Page "Like" Av...
• 14-Spr1-30. 50492 - Contest Score...
• 14-Spr1-40. 50538 - Sum of kth Dia...
• 14-Spr1-60. 50647 - Spiral
• 14-Spr2-20. 50442 - Polynomial...
• 14-Spr2-40. 50361 - Align Two Lists
• 14-Spr2-50. 50616 - Snake
• 14-Spr2-60. 50444 - n digit kth nu...
• 15-SprHW-20. 50446 - Snake
• 15-SprHW-30. 50788 - Eight Puzzle
• 15-SprHW-40. 50746 - Most Visited
• 15-SprHW-60. 50516 - Lines
• 15-SprPr2-20. 50509 - Reading Book

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Polynomial Addition

In general, polynomials are represented in the form (see the figure on right)

where there are variables with different non-negative integer exponents and each is multiplied with a coefficient. Polynomials involve only the operations of addition, subtraction, and multiplication.

e.g. the following is a quadratic polynomial (of variable x),
   2x2 - 4x + 7
which can be represented in the form
   2 2 -4 1 7 0

Question: Write a program that accepts two polynomils and returns sum of them.

Input specification
You will be first given two integers (n and m) where n is the length of the first and m is the length of the second polynomial.
The second line will contain n number pairs (coefficient and exponent) for the first polynomial. And, the third line will contain m number pairs for the second polynomial where 1 ≤ (n, m) ≤ 20 and coefficients are between -1000 and 1000 and exponents are between 0 and 20.
Note: Polynomials can be in any order.

Output specification
Show the resulting polynomial in descending order exponents.
 Note: Show information for any coefficient different than 0.

 Sample Input   
 3 3
 1 0 -5 8 3 14
 8 14 -3 10 9 8
 Sample Output   
 11 14 -3 10 4 8 1 0


Для отправки решений необходимо выполнить вход.

www.contester.ru