-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgift1.cpp
More file actions
61 lines (48 loc) · 1.05 KB
/
Copy pathgift1.cpp
File metadata and controls
61 lines (48 loc) · 1.05 KB
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
57
58
59
60
61
/*
ID: th3c0r11
TASK: gift1
LANG: C++14
*/
#include <iostream>
#include <algorithm>
#include <fstream>
#include <unordered_map>
#include <vector>
int main()
{
std::ifstream in{"gift1.in"};
std::ofstream out{"gift1.out"};
int np;
std::unordered_map<std::string, int> accounts;
std::vector<std::string> names;
std::string npstr;
std::getline(in, npstr);
np = std::atoi(npstr.c_str());
std::string null;
for (int i = 0; i < np; ++i) {
std::getline(in, null);
accounts[null] = 0;
names.push_back(null);
}
for (int i = 0; i < np; ++i) {
std::string name;
int amount;
int people;
std::getline(in, name);
in >> amount >> people;
std::getline(in, null);
if (people == 0)
continue;
int giveAmount = amount / people;
int keepAmount = amount % people;
accounts[name] += keepAmount;
accounts[name] -= amount;
for (int j = 0; j < people; ++j) {
std::string recipient;
std::getline(in, recipient);
accounts[recipient] += giveAmount;
}
}
for (const auto &name : names)
out << name << " " << accounts[name] << '\n';
}