#include<stdio.h>
#include<stdlib.h>//含malloc.h
#define LEN sizeof( Faction)
//一元多项式结构体
typedef struct Faction{
int coefficient;//系数
int exponent;//指数
struct Faction *next;
}Faction;
//创建链表
Faction *creat() {
Faction *head, *p1, *p2;
head = NULL;
p1 = p2 = (Faction*)malloc(LEN);
scanf("%d %d", &(p1->coefficient), &(p1->exponent));
p1->next = NULL;
while(p1->coefficient != -1 || p1->exponent != -1) {
if(head == NULL)
head = p1;
else
p2->next = p1;
p2 = p1;
p1 = (Faction*)malloc(LEN);
scanf("%d %d", &(p1->coefficient), &(p1->exponent));//此处可以顺便统数据个数
}
p2->next = NULL;
return head;
}
//输出链表
void Print(Faction *head) {
Faction *p;
p = head;
while(p != NULL) {
printf("%d %d", p->coefficient, p->exponent);//空格就是\
p = p->next;
}
}
//计算降幂
void Calculate(Faction *head) {
Faction *p;
p = head;
while(p != NULL) {
p->coefficient = p->coefficient * p->exponent;
p->exponent -= p->exponent;
if(p->coefficient == 0)
break;
p = p->next;
}
}
//
int main() {
Faction *head;
head = NULL;
head = creat();
Print(head);
return 0;
}