1002 A+B for Polynomials (25 分)(简单模拟,保留一位小数)

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805526272000000

注意:保留一位小数

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 0x3f3f3f3f;
typedef long long ll;
int main() {
int k;
double a[1005];
memset(a,0,sizeof(a));
cin >> k;
int x;
double y;
for(int i = 0; i < k; i++) {
cin >> x >> y;
a[x] += y;
}
cin >> k;
for(int i = 0; i <k; i++) {
cin >> x >> y;
a[x] += y;
}
k = 0;
for(int i = 1000; i >= 0; i--) {
if(a[i] != 0) k++;
}
cout << k;
for(int i = 1000; i >= 0; i--) {
if(a[i] != 0) printf(" %d %.1lf",i,a[i]);
}
return 0;
}

posted on 2019-10-22 23:55  一只小毛球  阅读(164)  评论(0编辑  收藏  举报

导航