美文网首页
1002 A+B for Polynomials

1002 A+B for Polynomials

作者: LinkLiKang | 来源:发表于2022-03-29 11:07 被阅读0次
    #include <cstdio>
    const int maxn = 1111;
    double p[maxn] = { };
    int main(){
        int k, n, count = 0;
        double a;
        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 < maxn; i++){
            if(p[i] != 0){
                count++;
            }
        }
        
        printf("%d", count);
        for (int i = maxn - 1; i >= 0; i--) {
            if(p[i] != 0){
                printf(" %d %.1f", i, p[i]);
            }
        }
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:1002 A+B for Polynomials

          本文链接:https://www.haomeiwen.com/subject/jvyvjrtx.html