【 数据结构(C语言)】 线性表顺序表示应用 (一)一元多项式的表示

1.稀疏多项式

#include <bits/stdc++.h>
using namespace std;
#define LIST_INIT_SIZE 25
typedef struct
{
    int *c;
    int *e;
    int length;
    int listsize;
}Sqlist;
int index;
void InitList_Sq(Sqlist &L)
{
    L.e = (int * )malloc(LIST_INIT_SIZE*sizeof(int));
    L.c = (int * )malloc(LIST_INIT_SIZE*sizeof(int));
    L.length = 0;
    L.listsize = LIST_INIT_SIZE;
}
void ListInsert_Sq(Sqlist  &L,int pos, int c,int e)
{
    L.e[pos] = e;
    L.c[pos] = c;
    L.length++;
}
int GetSum(Sqlist &L)
{
   int sum = 0;
   for (int i=0; i < L.length ; i++)
   {
       int tmp = L.c[i]*(int)pow(index,L.e[i]);
       sum += tmp;
   }
   return sum;
}
int main()
{
    Sqlist Sq;
    InitList_Sq(Sq);

    int m;
    scanf("%d",&m);

    for (int i=0; i<m; i++)
    {
        int  c,e;
        scanf("%d %d",&c,&e);
        ListInsert_Sq(Sq,i,c,e);
    }
    scanf("%d",&index);
    printf("%d\n",GetSum(Sq));
    return 0;
}
/*
2
1 1
1 1
1

2
55 55
66 66
1
*/

  

转载于:https://www.cnblogs.com/sxy-798013203/p/7763230.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值