1472. Ask for two polynomial and

Source: Internet
Author: User

Title Description:

Enter two polynomial to calculate their and.
Each polynomial has several pairs of integers, each set of integers, the first integer representing the coefficient (not 0), and the second integer representing the number of times of the item.
If 3 3 5-2 1 4 0 represents 3x^5-2 * x + 4 where the first 3 indicates that the polynomial is represented by three integer pairs.

Input:

The input is two lines, each representing two polynomial. An integer representing each item is given in descending order of the number of times. (The absolute value of the number is less than 1000, the coefficient absolute is less than 10000)

Output:

Integer pairs of output representations and polynomial in descending order (integer pairs with a factor of 0 are not output, integer pairs are separated by spaces, and the last integer pair does not add spaces)

Sample input:
3 3 5-2 1 4 04 2 3-1 2 1 1 3 0
Sample output:
3 5 2 3-1 2-1 1 7 0

#include <iostream>#include<cstring>#include<cstdio>//pay attention to FIRST processing!!! using namespacestd;intxishu1[1001];intcishu1[1001];intxishu2[1001];intcishu2[1001];intresult[1001];intMain () {intN,m,i;  while(cin>>N) {memset (XISHU1,0,sizeof(XISHU1)); memset (CISHU1,0,sizeof(CISHU1)); memset (XISHU2,0,sizeof(XISHU2)); memset (CISHU2,0,sizeof(CISHU2)); memset (Result,0,sizeof(result));  for(i=0; i<n;i++) {cin>>xishu1[i]>>Cishu1[i]; } CIN>>L;  for(i=0; i<m;i++) {cin>>xishu2[i]>>Cishu2[i]; }         for(i=0; i<n;i++) {Result[cishu1[i]]=Xishu1[i]; }         for(i=0; i<m;i++) {Result[cishu2[i]]+=Xishu2[i]; }        intfirst=1;  for(i= +; i>=0; i--)        {            if(Result[i]) {if(first) {cout<<result[i]<<" "<<i; First=0; }            Elsecout<<" "<<result[i]<<" "<<i; }} cout<<Endl; }    return 0;}

1472. Two polynomial and

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.