| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

已结贴   问题点数：20  回复次数：2

#include <stdio.h>
#include <malloc.h>

typedef struct
{
int cff;//系数
int exp;//指数
} datatype;

typedef struct Node
{
datatype data_1;
struct Node *next;

{
int xs;
int zs;
while(scanf("%d%d",&xs, &zs)
&& xs != 0
|| zs != 0)//输入00是结束
{
p->data_1.cff = xs;
p->data_1.exp = zs;
r->next = p;
r = p;
}
r->next = NULL;
}

{
r = l->next;
while( r != NULL)
{
q = r->next;
while( q != NULL)
{
if( q->data_1.exp > r->data_1.exp )
{
p->data_1.cff = r->data_1.cff;
p->data_1.exp = r->data_1.exp;
r->data_1.cff = q->data_1.cff;
r->data_1.exp = q->data_1.exp;
q->data_1.cff = p->data_1.cff;
q->data_1.exp = p->data_1.exp;
}
q = q->next;
}
r = r->next;
}
}

{
r = l;
while( r != NULL && r->next != NULL)
{
q = r->next;
while( q->next != NULL && q != NULL
&& (q->data_1.exp == q->next->data_1.exp))
{
p = q->next;
q->data_1.cff += p->data_1.cff;
q->next = p->next;
free(p);
}
r = r->next;
}

//清楚系数为0的项
r = l;
while(r != NULL && r->next != NULL)
{
if( r->next->data_1.cff == 0)
{
q = r->next;
r->next = q->next;
free(q);
}
r = r->next;
}
}

{
p = l_fir->next;
q = l_sec->next;
while( p != NULL && q != NULL )//表一表二中均有数据
{
if(p->data_1.exp == q->data_1.exp)
{

s->data_1.cff = p->data_1.cff + q->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
q = q->next;
}
else if(p->data_1.exp > q->data_1.exp)
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
}
else if(p->data_1.exp < q->data_1.exp)
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
}
r->next = s;
r = s;
}
while( p != NULL)//仅表一中有数据
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
r->next = s;
r =s;
}
while( q != NULL)//仅表二中有数据
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
r->next = s;
r =s;
}
r->next = NULL;

//清楚系数为0的项
while(r != NULL && r->next != NULL)
{
if( r->next->data_1.cff == 0)
{
q = r->next;
r->next = q->next;
free(q);
}
r = r->next;
}
}

{
k = p;
if(p->next == NULL)
printf("empty list\n");
while( p->next != NULL)
{
if( p->next->data_1.cff < 0)
{
if(p == k)
printf("-");
else
printf("- ");
printf("%d^%d ", -p->next->data_1.cff, p->next->data_1.exp);
}
else if(p != k && p->next->data_1.cff > 0)
{
printf("+ ");
printf("%d^%d ", p->next->data_1.cff, p->next->data_1.exp);
}
else if(p == k && p->next->data_1.cff > 0)
{
printf("%d^%d ", p->next->data_1.cff, p->next->data_1.exp);
}
p = p->next;
}

}
{
k = p;
while(p != NULL && p->next != NULL)
{
q = p->next;
p->next = q->next;
free(q);
}
}

void main()
{

printf("请输入第一个多项式：\n");
pa = create_list();
Select_sort(pa);
merge_list(pa);
printf("排序化简后的多项式为：\n");
printf("                      \n");
result_out(pa);
printf("\n                    \n\n");

printf("请输入第二个多项式：\n");
pb = create_list();
Select_sort(pb);
merge_list(pb);
printf("排序化简后的多项式为：\n");
printf("                       \n");
result_out(pb);
printf("\n                     \n\n");

printf("相加后的多项式为：\n");
printf("                       \n");
result_out(pc);
printf("\n                      \n\n");

free_list(pa);
free(pa);
free_list(pb);
free(pb);
free_list(pc);
free(pc);
}

得分:20

```#include <stdio.h>
#include <malloc.h>

typedef struct
{
int cff;//系数
int exp;//指数
} datatype;

typedef struct Node
{
datatype data_1;
struct Node *next;

{
int xs;
int zs;
while (scanf("%d%d", &xs, &zs)
&& xs != 0
|| zs != 0)//输入00是结束
{
p->data_1.cff = xs;
p->data_1.exp = zs;
r->next = p;
r = p;
}
r->next = NULL;
}

{
r = l->next;
while (r != NULL)
{
q = r->next;
while (q != NULL)
{
if (q->data_1.exp > r->data_1.exp)
{
p->data_1.cff = r->data_1.cff;
p->data_1.exp = r->data_1.exp;
r->data_1.cff = q->data_1.cff;
r->data_1.exp = q->data_1.exp;
q->data_1.cff = p->data_1.cff;
q->data_1.exp = p->data_1.exp;
}
q = q->next;
}
r = r->next;
}
}

{
r = l;
while (r != NULL && r->next != NULL)
{
q = r->next;
while (q->next != NULL && q != NULL
&& (q->data_1.exp == q->next->data_1.exp))
{
p = q->next;
q->data_1.cff += p->data_1.cff;
q->next = p->next;
free(p);
}
r = r->next;
}

//清楚系数为0的项
r = l;
while (r != NULL && r->next != NULL)
{
if (r->next->data_1.cff == 0)
{
q = r->next;
r->next = q->next;
free(q);
}
r = r->next;
}
}

{
p = l_fir->next;
q = l_sec->next;
while (p != NULL && q != NULL)//表一表二中均有数据
{
if (p->data_1.exp == q->data_1.exp)
{

s->data_1.cff = p->data_1.cff + q->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
q = q->next;
}
else if (p->data_1.exp > q->data_1.exp)
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
}
else if (p->data_1.exp < q->data_1.exp)
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
}
r->next = s;
r = s;
}
while (p != NULL)//仅表一中有数据
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
r->next = s;
r = s;
}
while (q != NULL)//仅表二中有数据
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
r->next = s;
r = s;
}
r->next = NULL;

//清楚系数为0的项
while (r != NULL && r->next != NULL)
{
if (r->next->data_1.cff == 0)
{
q = r->next;
r->next = q->next;
free(q);
}
r = r->next;
}
}

{
p = l_fir->next;
q = l_sec->next;
while (p != NULL && q != NULL)//表一表二中均有数据
{
if (p->data_1.exp == q->data_1.exp)
{

s->data_1.cff = p->data_1.cff - q->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
q = q->next;
}
else if (p->data_1.exp > q->data_1.exp)
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
}
else if (p->data_1.exp < q->data_1.exp)
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
}
r->next = s;
r = s;
}
while (p != NULL)//仅表一中有数据
{
s->data_1.cff = p->data_1.cff;
s->data_1.exp = p->data_1.exp;
p = p->next;
r->next = s;
r = s;
}
while (q != NULL)//仅表二中有数据
{
s->data_1.cff = q->data_1.cff;
s->data_1.exp = q->data_1.exp;
q = q->next;
r->next = s;
r = s;
}
r->next = NULL;

//清楚系数为0的项
while (r != NULL && r->next != NULL)
{
if (r->next->data_1.cff == 0)
{
q = r->next;
r->next = q->next;
free(q);
}
r = r->next;
}
}

{
k = p;
if (p->next == NULL)
printf("empty list\n");
while (p->next != NULL)
{
if (p->next->data_1.cff < 0)
{
if (p == k)
printf("-");
else
printf("- ");
printf("%d^%d ", -p->next->data_1.cff, p->next->data_1.exp);
}
else if (p != k && p->next->data_1.cff > 0)
{
printf("+ ");
printf("%d^%d ", p->next->data_1.cff, p->next->data_1.exp);
}
else if (p == k && p->next->data_1.cff > 0)
{
printf("%d^%d ", p->next->data_1.cff, p->next->data_1.exp);
}
p = p->next;
}

}
{
k = p;
while (p != NULL && p->next != NULL)
{
q = p->next;
p->next = q->next;
free(q);
}
}

void main()
{

printf("请输入第一个多项式：\n");
pa = create_list();
Select_sort(pa);
merge_list(pa);
printf("排序化简后的多项式为：\n");
printf("                      \n");
result_out(pa);
printf("\n                    \n\n");

printf("请输入第二个多项式：\n");
pb = create_list();
Select_sort(pb);
merge_list(pb);
printf("排序化简后的多项式为：\n");
printf("                       \n");
result_out(pb);
printf("\n                     \n\n");

printf("相加后的多项式为：\n");
printf("                       \n");
result_out(pc);
printf("\n                      \n\n");

printf("相减后的多项式为：\n");
printf("                       \n");
pd = del_list(pa, pb);
result_out(pd);
printf("\n                      \n\n");

free_list(pa);
free(pa);
free_list(pb);
free(pb);
free_list(pc);
free(pc);
free_list(pd);
free(pd);
}```

• cainiao一枚 于 2016-06-03 21:34 送鲜花  3朵   附言：我很赞同 谢谢
得分:0

• 3
• 1/1页
• 1