0%

1002 A+B for Polynomials

https://pintia.cn/problem-sets/994805342720868352/exam/problems/994805526272000000

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include<string>
#include<cstdio>
#include<map>

using namespace std;

int main() {
int k1;
cin >> k1;
map<int, float, greater<>> m;
for (int i = 0; i < k1; i++) {
int key;
float value;
cin >> key;
cin >> value;
m[key] += value;
if (m[key]==0) {
m.erase(key);
}
}
int k2;
cin >> k2;
for (int i = 0; i < k2; i++) {
int key;
float value;
cin >> key;
cin >> value;
m[key] += value;
if (m[key]==0) {
m.erase(key);
}
}
cout << m.size();
for (auto &pair: m) {
if (pair.second != 0) {
printf(" %d %.1f", pair.first, pair.second);
}
}
return 0;
}