PAT甲级1002题(多项式加)


1.题目介绍

1002

polynomial:多项式

exponent:指数

coefficient:系数

2.考察点,难度

高精度题,难度易

3.解题代码

#include<iostream>
using namespace std;

int main()
{
    int k, n, sum = 0;
    double a, p[1001] = {0};
    scanf("%d", &k);
    for (int i = 0; i < k; i++){
        scanf("%d%lf", &n, &a);
        p[n] += a;
    }
    scanf("%d", &k);
    for (int i = 0; i < k; i++){
        scanf("%d%lf", &n, &a);
        p[n] += a;
    }
    for (int i = 0; i < 1001; i++) if (p[i]) sum++;
    printf("%d", sum);
    for (int i = 1000; i >= 0; i--) if (p[i]) printf(" %d %.1f", i, p[i]);
    return 0;
}

4.原题地址

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


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