-
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