//库函数头文件包含
#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#pragma warning(disable : 4996)
using namespace std;
//函数状态码定义
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef struct {
int c;//系数
int e;//指数
}term, ElemType;//将系数和指数打包为一个数据项
typedef struct LNode {
ElemType elem;
struct LNode* next;
}*LinkList, LNode;
typedef LinkList Poly;
Status PolyInit(Poly& P)
{
P = (LNode*)malloc(sizeof(LNode));
if (!P)exit(OVERFLOW);
P->next = NULL;
return OK;
}
void PolyCreate(Poly& P)
{
int a, b, k = 0; char c;
LNode* cur, * rear = P;
while (scanf("%d%d", &a, &b) == 2)//此处依据scanf返回值判定并不起作用,当正常输入两两一组数时,并不会结束循环,
{ //只有当输入奇数个数时才会因返回1而结束,真正起作用的是getchar读入的判定
k++;
cur = (LNode*)malloc(sizeof(LNode));
if (!cur)exit(OVERFLOW);
cur->elem.c = a;
cur->elem.e = b;
rear->next = cur;
rear = rear->next;
if (b == 0)break;
c = getchar();
if (c == '\n')break;
}
if (k == 0)return;
rear->next = NULL;
}
void PolyPrint(Poly& P)
{
LNode* p = P->next;
if (!p)
{
cout << 0 << " " << 0 << endl;
return;
}
while (p)
{
if (p->next != NULL)
cout << p->elem.c << " " << p->elem.e << " ";
else
cout << p->elem.c << " " << p->elem.e;
p = p->next;
}
cout << endl;
}
void KaiDao(Poly& P)
{
LNode* p = P->next, * lep = P;;
while (p)
{
if (p->elem.e == 0)
{
lep->next = p->next;
free(p);
p = lep->next;
}
else
{
p->elem.c = p->elem.c * p->elem.e;
p->elem.e--;
lep = lep->next;
p = p->next;
}
}
}
int main()
{
Poly P;
PolyInit(P);
PolyCreate(P);
KaiDao(P);
PolyPrint(P);
return 0;
}