PAT甲级1009题(多项式乘)


1.题目介绍

1009

polynomial:多项式

exponent:指数

coefficient:系数

2.考察点,难度

高精度题,动态数组,难度易

3.解题代码

#include<cstdio>
using namespace std;

double result[2001] = {0};

int main()
{
    int k1, k2, exp2;
    double coe2;
    scanf("%d", &k1);

    // 开动态数组
    int *exp1 = new int[k1];
    double *coe1 = new double[k1];

    for (int i = 0; i < k1; i++) scanf("%d%lf", exp1+i, coe1+i);
    scanf("%d", &k2);
    for (int i = 0; i < k2; i++){
        scanf("%d%lf", &exp2, &coe2);
        for (int j = 0; j < k1; j++)
            result[exp1[j] + exp2] += coe1[j] * coe2;
    }

    int k = 0;
    for (int i = 0; i < 2001; i++)
        if (result[i] != 0) k++;
    printf("%d",k);
    for (int i = 2000; i >= 0; i--)
        if (result[i] != 0)
            printf(" %d %.1f", i, result[i]);

    return 0;
}

4.原题地址

https://pintia.cn/problem-sets/994805342720868352/problems/994805509540921344


文章作者: Peyton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Peyton !
  目录