您的位置:首页 > 其它

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

2017-10-22 16:36 561 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: