#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<iostream>
using namespace std;
typedef double ListItem;
typedef ListItem* addr;
typedef struct alist *List;
typedef struct alist
{
int n,curr;
int maxsize;
ListItem *table;
}Alist;
List ListInit(int size)
{
List L=(List)malloc(sizeof *L);
L->table=(ListItem *)malloc(size*sizeof(ListItem));
L->maxsize=size;
L->n=0;
return L;
}
//都是接口的定义过程,已检查完了
List add(List L1,List L2)
{
int j;
for(j=0;j<251001;j++)
{
L1->table[j]+=L2->table[j];
}
return L1;
}
List sub(List L1,List L2)
{
int j;
for(j=0;j<251001;j++)
{
L1->table[j]-=L2->table[j];
}
return L1;
}
//乘法函数
List multi(List L1,List L2)
{
List L5;L5=ListInit(251001);
int i,j;
for(i=0;i<501;i++)
{
for(j=0;j<501;j++)
{
L5->table[i+j]+=L1->table[i]*L2->table[j];
}
}
return L5;
}
void oper(List L1)//输出函数 1
{
int i;
int flag=0,flag1=0;
for(i=251001;i>=0;i--)
{
if(L1->table[i]==0) continue;
else if(L1->table[i]>0&&L1->table[i]!=1)
{
if(flag==0)
{
cout<<setprecision(6)<<L1->table[i];flag=1;
}
else
cout<<"+"<<setprecision(6)<<L1->table[i];
}
else if(L1->table[i]==1)
{
if(flag==0) flag++;
else printf("+");
}
else if(L1->table[i]<0&&L1->table[i]!=-1)
{
if(flag==0)
{
cout<<setprecision(6)<<L1->table[i];flag=1;
}
else
cout<<setprecision(6)<<L1->table[i];
}
else if(L1->table[i]==-1)
{
if(flag==0) flag++;
printf("-");
}
if(i>1)
{
printf("x^%d",i);flag1=1;
}
else if(i==1)
{
printf("x");flag1=1;
}
}
if(!flag1)
{
printf("0");
}
}
//以下为函数的主体部分,以上是自写的方程
double a[21][510];
char fuhao[21];
int main()
{
int k,k1,k2,b1;
int i,j;
double a1;
List L1,L2,L4;
L1=ListInit(251001);L2=ListInit(251001);L4=ListInit(251001);
scanf("%d",&k);getchar();
for(i=0;i<k;i++)
{
scanf("%d",&k1);getchar();
for(j=0;j<k1;j++)
{
scanf("%lf %d",&a1,&b1);getchar();
a[i][b1]=a1;
}
}
for(i=0;i<k;i++)
{
scanf("%c",&fuhao[i]);
}
for(i=0;i<k;i++)
{
if(i==0)//存入储蓄表,不进行操作
{
for(j=0;j<510;j++)
{
L1->table[j]=a[0][j];
}
continue;//不计算
}
else if(i>=1)//存入预备表,与储蓄表一起计算
{
for(j=0;j<510;j++)
{
L2->table[j]=a[i][j];
}
}
if(fuhao[i-1]=='+')
{
L1=add(L1,L2);
}
else if(fuhao[i-1]=='-')
{
L1=sub(L1,L2);
}
else if(fuhao[i-1]=='*')
{
L1=multi(L1,L2);
}
}
oper(L1);
return 0;
}
10-14