user-0 提问: 为什么我这个最后输出不出来啊，有大神帮忙看下吗？

回复:
user: user-1
content: #include<stdio.h> #include<stdlib.h> #include<malloc.h>  //#define NULL 0 //#define NULL ((void *)0)  typedef struct Polynode {     int coef;  //因子     int exp;   //幂     struct Polynode *next; }Polynode , *Polylist;  Polylist polycreate( ) {     Polynode *rear, *head, *s;      int c, e;      rear=head=(Polynode *)malloc(sizeof(Polynode));     scanf("%d%d", &c, &e);      while(c) {         s = (Polynode*)malloc(sizeof(Polynode));         s->coef=c;         s->exp=e;         rear->next=s;         rear=s;         scanf("%d%d",&c,&e);     }     rear->next=NULL;      return(head); }    static void insert_node(Polylist phead, Polylist new_node) {     Polylist pcur, pprev;      pprev = phead;     pcur = phead->next;      while (pcur && pcur->exp != new_node->exp) {         pprev = pcur;         pcur = pcur->next;     }     if (!pcur) {         pprev->next = new_node;         return;     }      pcur->coef += new_node->coef;     free(new_node);     if (pcur->coef == 0) {         pprev->next = pcur->next;         free(pcur);     } }  Polylist multyploy(Polylist pa, Polylist pb) {     Polylist pa_node, pb_node, pc_node, pc;     int coef, exp;       pc = (Polynode*)malloc(sizeof(Polynode));     if (!pc)         return NULL;      pa_node = pa->next;     pb_node = pb->next;     while (pa_node) {          while (pb_node) {             coef = pa_node->coef * pb_node->coef;             exp = pa_node->exp + pb_node->exp;              pc_node = (Polylist)malloc(sizeof(Polynode));             if (!pc_node)                 exit(0);             pc_node->coef = coef;             pc_node->exp = exp;             pc_node->next = NULL;              insert_node(pc, pc_node);             pb_node = pb_node->next;         }         pa_node = pa_node->next;         pb_node = pb->next;    //保证pa的节点和pb的每个节点相乘     }      return pc; #if 0     Polynode *t1,*t2,*t3,*t,*rear,*p;     int c, e;     t1=pa->next;     t2=pb->next;     p=(Polynode*)malloc(sizeof(Polynode));     p->next=NULL;     rear=p;     while(t2)     {         t3=(Polynode*)malloc(sizeof(Polynode));         t3->coef=t1->coef*t2->coef;         t3->exp=t1->exp+t2->exp;         t3->next=NULL;         rear->next=t3;         rear=t3;         t2=t2->next;     }     t1=t1->next;     while(t1)     {         t2=pb->next;         rear=p;         while(t2)         {             e=t1->exp+t2->exp;             c=t1->coef*t2->coef;             while(rear->next&&rear->next->exp<e)                 rear=rear->next;             if(rear->next&&rear->next->exp==e)             {                 if(rear->next->coef+c)                     rear->next->coef+=c;                 else                 {                     t=rear->next;                     rear->next=t->next;                     free(t);                  }             }             else             {                 t=(Polynode*)malloc(sizeof(Polynode));                 t->coef=c;                 t->exp=e;                 t->next=rear->next;                 rear->next=t;                 rear=rear->next;             }         }         t1=t1->next;     }     t2=p;     p=p->next;     free(t2);     return p; #endif }  void print(Polylist p) {     p = p->next;     while(p)     {         printf("%d", p->coef);         printf("*x^%d",p->exp);         if(p->next!=NULL)             printf(" + ");         p = p->next;     }     printf("\n"); }  //void main(int argc, char* argv[]) int main(int argc, char* argv[]) {     Polylist pa, pb,pc;   //定义三个表示多项式的链表      pa = polycreate();  //创建pa链表     //print(pa);      //将加法的结果用一个多项式格式显示在输出设备上     pb = polycreate();  //创建pb链表     //print(pb);      //将加法的结果用一个多项式格式显示在输出设备上     pc = multyploy(pa, pb);   //做乘法法，结果保存在pc链表上     print(pc);      //将加法的结果用一个多项式格式显示在输出设备上 } 供参考～

user: user-2
content: 纯粹是为了这50分  算法太复杂了，刚好有时间，重新实现了一遍。大抵如下：   #include<stdio.h> #include<stdlib.h> #include<malloc.h>  typedef struct Polynode {     int coef;  //因子     int exp;   //幂     struct Polynode *next; } Polynode , *Polylist;  Polylist polycreate( ) {     Polynode *rear, *head, *s;     int c, e;      head = NULL;     rear = NULL;      while (1) {         scanf("%d%d",&c,&e);         if (c == 0)             break;          s = (Polynode *) malloc(sizeof(Polynode));         s->coef = c;         s->exp = e;         s->next = NULL;          if (head == NULL)             head = s;          if (rear != NULL) {             rear->next = s;         }         rear = s;     };      return head; }  Polylist multyploy(Polylist pa, Polylist pb) {     Polynode *n, *n1, *n2, *rslt, *rslt_rear, *new_item;     int coef, exp;      rslt = NULL;     rslt_rear = NULL;      for (n1 = pa; n1 != NULL; n1 = n1->next) {         for (n2 = pb; n2 != NULL; n2 = n2->next) {             coef = n1->coef*n2->coef;             exp = n1->exp + n2->exp;              // Find the right item to add the new result             for (n = rslt; n != NULL; n = n->next) {                 if (n->exp == exp)                     break;                 if (n->exp < exp && n->next != NULL && n->next->exp > exp)                     break;             }              // if item with identified exponent exists in result, just update its coefficient             if (n != NULL && n->exp == exp) {                 n->coef += coef;                 continue;             }              // new item needed             new_item = (Polynode *) malloc(sizeof(Polynode));             new_item->coef = coef;             new_item->exp = exp;             new_item->next = NULL;              // insert the new item, note sort if performed incrementally             if (n == NULL) {                 if (rslt == NULL) {                     rslt = new_item;                     rslt_rear = rslt;                 } else {                     rslt_rear->next = new_item;                     rslt_rear = new_item;                 }             } else {                 new_item->next = n->next;                 n->next = new_item;             }         } // iterate over the second polynominal     } // iterate over the first polynominal      return rslt; }  void print(Polylist p) {     while(p)     {         printf("%d", p->coef);         printf("*x^%d",p->exp);         if(p->next!=NULL)             printf(" + ");         p = p->next;     }     printf("\n"); }  void free_poly_list(Polylist head) {     Polynode *n0, *n1;     for (n0 = head; n0 != NULL; n0 = n1) {        n1 = n0->next;        free(n0);     } }  int main(int argc, const char* argv[]) {     Polylist pa, pb,pc;       //定义三个表示多项式的链表      pa = polycreate();        //创建pa链表     pb = polycreate();        //创建pb链表     pc = multyploy(pa, pb);   //做乘法法，结果保存在pc链表上     print(pc);      free_poly_list(pa);     free_poly_list(pb);     free_poly_list(pc);      return 0; }