PAT甲级 1002 A+B for Polynomials (25)

来源:互联网 发布:好听的淘宝会员名大全 编辑:程序博客网 时间:2024/06/10 17:58
#include <iostream>double res[1001]={0};using namespace std;int main(int argc, const char * argv[]) {    // insert code here...    int k1,k2;    cin>>k1;    for (int i=0; i<k1; i++) {        int exp;        double cof;        scanf("%d %lf",&exp,&cof);        res[exp]+=cof;    }    cin>>k2;    for (int i=0; i<k2; i++) {        int exp;        double cof;        scanf("%d %lf",&exp,&cof);        res[exp] += cof;    }    int res_k=0;    for (int i=0; i<1001; i++) {        if (res[i]!=0) {            res_k++;        }    }    cout<<res_k;    for (int i=1000; i>=0; i--) {        if (res[i]!=0) {            printf(" %d %.1lf",i,res[i]);        }    }    return 0;}

原创粉丝点击