###### PAT 3-04 一元多项式的乘法与加法运算（C语言实现）

 序号 输入 输出 1 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  2 2 1 2 1 0 2 1 2 -1 0  1 4 -1 0 2 2  3 2 -1000 1000 1000 0 2 1000 1000 -1000 0  -1000000 2000 2000000 1000 -1000000 0 0 0  4 0 1 999 1000  0 0 999 1000 

#include<stdio.h>
#include<stdlib.h>

typedef struct node *ptrNode;
typedef ptrNode Position;//中间节点
typedef int ElementType;
struct node{
ElementType Coefficient;
ElementType Exponent;
Position next;
};

{
return L->next == NULL;
}

{
int coe,exp;
head = (struct node*)malloc(sizeof(struct node));    //生成新结点

while(n--){
scanf("%d%d",&coe,&exp);
p = (struct node*)malloc(sizeof(struct node));
p->Coefficient = coe;
p->Exponent = exp;
r->next = p;
r = p;
}
r->next = NULL;
}

{
Position ha, hb;
int temp;

ha = a->next;
hb = b->next;

c = (struct node*)malloc(sizeof(struct node));
r = c;
while((ha != NULL)&&(hb != NULL)){
p = (struct node*)malloc(sizeof(struct node));
if(ha->Exponent < hb->Exponent){
p->Exponent = hb->Exponent;
p->Coefficient = hb->Coefficient;
hb = hb->next;
r->next = p;
r = p;
}
else if(ha->Exponent > hb->Exponent){
p->Exponent = ha->Exponent;
p->Coefficient = ha->Coefficient;
ha = ha->next;
r->next = p;
r = p;
}
else{
temp = ha->Coefficient + hb->Coefficient;
if(temp != 0){
p->Exponent = ha->Exponent;
p->Coefficient = temp;
r->next = p;
r = p;
}
hb = hb->next;
ha = ha->next;
}
}
if(ha == NULL){
while(hb != NULL){
p = (struct node*)malloc(sizeof(struct node));
p->Exponent = hb->Exponent;
p->Coefficient = hb->Coefficient;
hb = hb->next;
r->next = p;
r = p;
}
}
if(hb == NULL){
while(ha != NULL){
p = (struct node*)malloc(sizeof(struct node));
p->Exponent = ha->Exponent;
p->Coefficient = ha->Coefficient;
ha = ha->next;
r->next = p;
r = p;
}
}

r->next = NULL;
return c;
}

{
Position ha, hb;
ha = a->next;
hb = b->next;
//c = (struct node*)malloc(sizeof(struct node));
//c->next = NULL;
c = creatList(0);
if(ha == NULL || hb == NULL){
return c;
}

while(ha != NULL ){
tempC = (struct node*)malloc(sizeof(struct node));
r = tempC;
hb = b->next;
while(hb != NULL){
p = (struct node*)malloc(sizeof(struct node));
p->Exponent = ha->Exponent + hb->Exponent;
p->Coefficient = ha->Coefficient*hb->Coefficient;
hb = hb->next;
r->next = p;
r = p;
}
r->next = NULL;

//        tempC->next = NULL;
//        }
ha = ha->next;
}
return c;

}
{
int flag = 0;

hc = L->next;
if(hc == NULL)
printf("0 0");
while(hc != NULL){
if(flag)
printf(" ");
else
flag = 1;
printf("%d %d",hc->Coefficient,hc->Exponent);
hc = hc->next;
}
}

int main(void)
{
int n1,n2;

scanf("%d",&n1);
L1 = creatList(n1);
scanf("%d",&n2);
L2 = creatList(n2);

L4 = mul_List(L1,L2);
printList(L4);
printf("\n");
printList(L3);

return 0;
}



#### 一元多项式的乘法运算（C语言）实现

2017-09-01 08:59:50

#### PAT 一元多项式的乘法与加法运算(链表 c++版)

2015-09-09 22:45:30

#### 一元多项式的乘法与加法运算

2016-03-12 23:25:17

#### 多项式的加减法以及乘法的C语言实现

2014-05-25 16:30:38

#### 链表实现多项式加法和乘法（C语言实现）

2010-12-03 16:32:00

#### 简单的多项式乘法实现程序 C语言

2010年02月09日 4KB 下载

#### 多项式乘法（C语言）

2009年06月14日 21KB 下载

#### 一元多项式的相乘（C链表实现）.

2011年07月25日 153KB 下载

#### c语言实现多项式乘法

2011年12月13日 257KB 下载

#### 多项式相乘（C语言）

2013-07-14 16:07:15

## 不良信息举报

PAT 3-04 一元多项式的乘法与加法运算（C语言实现）