#include<stdio.h>
int main()
{
int i,j;
int a[21][21] = { 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 3, 0,-5, 6,-2,
0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, 0, 2, 1, 0};
int b[21][21] = { 5, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-7, 0, 0, 3, 0,
20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, 0, 0, 1, 0,};
int c[21][21] = { 0 }, d[42][42] = { 0 };
for (i = 0;i < 21;i++) // 两多项式相加
{
c[0][i] = a[0][i] + b[0][i]; // 系数相加
if (a[1][i] > b[1][i]) // 指数不变
c[1][i] = a[1][i];
else
c[1][i] = b[1][i];
}
for (i = 0;i < 21;i++) // 两多项式相乘
{
for (j = 0;j < 21;j++)
{
d[0][i + j] += a[0][i] * b[0][j]; // 系数相乘
if (a[0][i] != 0 && b[0][j] != 0) // 系数不为 0 ,指数相加
{
d[1][i + j] = a[1][i] + b[1][j];
}
}
}
for (i = 0;i < 21;i++) // 输出两多项式的和
if (c[0][i] != 0)
printf("%d %d ", c[0][i], c[1][i]);
printf("\b\b\n"); // 按题目要求删除末尾的空格
for (i = 0;i < 42;i++) // 输出两多项式的积
if (d[0][i] != 0)
printf("%d %d ", d[0][i], d[1][i]);
printf("\b\b\n"); // 按题目要求删除末尾的空格
return 0;
}