Croper
发表于 2018-12-25 02:28:42
本帖最后由 Croper 于 2018-12-25 02:30 编辑
我用Dev改了个scanf_s就没问题了啊
https://fishc.com.cn/https://xxx.ilovefishc.com/album/201812/25/022727usuqa0vu09vvf9ii.jpg
Croper
发表于 2018-12-25 02:53:49
刚刚忘了改纯C环境,这下可以了
#include <stdio.h>
#include <stdlib.h>
typedef int bool;
#define true 1
#define false 0
typedef struct node
{
int coef, exp;
struct node*next;
} NODE;
NODE * multiplication(NODE *, NODE *);
void input(NODE *);
void output(NODE *);
NODE* Link(NODE* p,int i) //?????,???i???,i?0??
{
int j;
for (j = 0; j <= i; j++)
{
p = p->next;
if (p == NULL) return NULL;
}
return p;
}
int Length(NODE* p) //?????,????,
{
int j=0;
while (p->next != NULL)
{
j++;
p = p->next;
}
return j;
}
void Append(NODE* p, int coef0, int exp0)//???????????????????,
{
p->next = (NODE*)malloc(sizeof(NODE));
p = p->next;
p->coef = coef0;
p->exp = exp0;
p->next=NULL;
}
void DeleteLinklist(NODE* head)//????
{
NODE *pPre;
while (head != NULL)
{
pPre = head;
head = head->next;
free(pPre);
}
}
NODE * multiplication(NODE *p1, NODE *p2) //????
{
NODE* ans,*p3;
NODE* Temp1,* Temp2;
int i,j;
p3 = (NODE*)malloc(sizeof(NODE)); //????p3
ans = p3; //ans??p3????,????
int len = Length(p1) + Length(p2)-1; //p3?????=?????????
for (i = 0; i < len; i++) //????p3????
{
Append(p3, 0, i);
p3=p3->next;
for (j = 0; j <= i; j++)
{
Temp1 = Link(p1,j);
Temp2 = Link(p2, i - j);
if ((Temp1!=NULL)&&(Temp2!=NULL)) p3->coef += (Temp1->coef*Temp2->coef);
}
}
return ans;
}
void input(NODE * p) //?????,?????????
{
int a, b;
int i = 0;
rewind(stdin);
while(scanf("<%d,%d>,", &a, &b)) //????,????????a?b?
{
for (i; i < b; i++)
{
Append(p, 0, i); //????,????=b
p=p->next;
}
Append(p, a, b); //??
p=p->next;
i++;
}
}
void output(NODE * head)
{
bool b = false; //???????????
while (head->next != NULL)
{
head = head->next;
if (head->coef != 0)
{
b = true; //??????????0,????????
printf("<%d,%d>,", head->coef, head->exp);
}
}
if (!b) printf("<0,0>,"); //??????????,?????0???,??<0,0>
printf("\n");
}
int main()
{
int i;
NODE * head1, *head2, *head3;
head1 = (NODE *)malloc(sizeof(NODE));
input(head1);
head2 = (NODE *)malloc(sizeof(NODE));
input(head2);
head3 = multiplication(head1, head2);
output(head3);
DeleteLinklist(head1);
DeleteLinklist(head2);
DeleteLinklist(head3);
return 0;
}
Croper
发表于 2018-12-25 02:57:03
症结在与你把。。。。Append(NODE*& p,..)的引用符号删了,删除了之后你又没有手动加一个移位,这样只会在一个地方反复读,当然什么东西都出不来
C语言里不能这么玩我不知道是我的问题。。。但是你也要知道你到底干了点啥啊。。。
lemon3
发表于 2018-12-25 11:37:11
Croper 发表于 2018-12-25 02:57
症结在与你把。。。。Append(NODE*& p,..)的引用符号删了,删除了之后你又没有手动加一个移位,这样只会在 ...
谢谢大哥!!!
lemon3
发表于 2018-12-25 13:42:24
Croper 发表于 2018-12-22 10:24
请问这个有没有不改变预设代码写的方法?!