-
Notifications
You must be signed in to change notification settings - Fork 0
/
1002.cpp
40 lines (38 loc) · 920 Bytes
/
1002.cpp
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
#include<iostream>
#include<map>
using namespace std;
void inputAdd(map<int, double> &m) {
int n;
cin >> n;
for (int i = 0; i < n; i ++) {
int key;
double value;
cin >> key >> value;
if (m.count(key) == 0) m[key] = value;
else m[key] += value;
}
}
int main()
{
map<int, double> m;
inputAdd(m);
inputAdd(m);
int count = 0;
for(auto &v: m) {
if(v.second != 0) count++;
}
cout << count;
// cout << m.size();
if (m.size() > 0) {
map<int, double>::iterator it = m.end();
map<int, double>::iterator end = m.begin();
bool flag = true;
for(it --; it != end || flag; it --) {
// cout << " " << it->first << " " << it->second;
if (it->second != 0)
printf(" %d %.1f", it->first, it->second);
if(it == end) break;
}
}
return 0;
}