-
Notifications
You must be signed in to change notification settings - Fork 0
/
1002_a_plus_b_ploy.cpp
57 lines (50 loc) · 1.16 KB
/
1002_a_plus_b_ploy.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <iomanip>
#include <stdio.h>
using namespace std;
void record(std::map<int, float> &record, string p)
{
istringstream iss(p);
double c;
iss >> c; //skip the first number
for (int ploy; iss >> ploy; )
{
iss >> c;
record[ploy] += c;
}
}
int main(int argc, char const *argv[])
{
/* code */
string p1, p2;
map<int, float> ploy_record;
while (getline(cin, p1) && getline(cin, p2))
{
ploy_record.clear();
record(ploy_record, p1);
record(ploy_record, p2);
int num = ploy_record.size();
int zero_num = 0;
for (auto pair : ploy_record)
{
if (pair.second == 0)
{
zero_num++;
}
}
cout << num - zero_num;
for (auto pair = ploy_record.rbegin(); pair != ploy_record.rend(); pair++)
{
if (!pair->second)
continue;
cout << ' ' << pair->first;
cout << ' ';
printf("%.1f", pair->second);
}
cout << endl;
}
return 0;
}