设计函数分别求两个一元多项式的乘积与和。
输入格式:
输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。
输出格式:
输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。零多项式应输出0 0
。
输入样例:
4 3 4 -5 2 6 1 -2 0
3 5 20 -7 4 3 1
输出样例:
15 24 -25 22 30 21 -10 20 -21 8 35 6 -33 5 14 4 -15 3 18 2 -6 1
5 20 -4 4 -5 2 9 1 -2 0
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
const int maxn=1000010; //两个多项式指数取上限时为10的6次方
int K1,K2; //输入多项式的项个数
int ans1[maxn],ans2[maxn]; //ans1是乘法。ans2是加法
int a,b; //每一项的系数和指数
struct Node{
int e;
int m;
};
vector<Node> P;
vector<Node> ansp1,ansp2; //ansp1是乘法,ansp2是加法
int main()
{
while(scanf("%d",&K1)!=EOF)
{
//memset(P1,0,sizeof(P1));
memset(ans1,0,