7-17 一元多项式的加法 (20 分)
设计程序求两个一元多项式的和。
输入格式:
输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数。数字间以空格分隔。
输出格式:
输出1行,以指数递降方式输出和多项式非零项的系数和指数(保证不超过整数的表示范围)。数字间以空格分隔,但结尾不能有多余空格。零多项式应输出0 0。
输入样例:
4 3 4 -5 2 6 1 -2 0
3 5 20 -7 4 3 1
输出样例:
5 20 -4 4 -5 2 9 1 -2 0
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
typedef struct Node* list;
struct Node
{
int c;
int e;
list next;
};
int n;
list Read()
{
list head,rear,s;
int c, e;
head = (list)malloc(sizeof(struct Node));
rear = head;
for(int i = 0; i < n; i ++)
{
scanf("%d %d",&c,&e);
s = (list)malloc(sizeof(struct Node));
s->c = c;
s->e = e;
rear-