您的位置:首页 > 编程语言 > C语言/C++

1002. A+B for Polynomials (25)

2016-01-16 17:56 357 查看
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int main(){
std::vector<float> coef(1001, 0);

for(int i = 0; i < 2; ++i){
int k, exp;
float c;
scanf("%d", &k);

for (int j = 0; j < k; ++j){
scanf("%d%f", &exp, &c);
coef[exp] += c;
}
}

int total = 0;
for (size_t i = 0; i < coef.size(); ++i){
if(coef[i]) ++total;
}

printf("%d", total);

for(int i = 1000; i >= 0; --i){
if(coef[i]) printf(" %d %.1f", i, coef[i]);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息