-
Notifications
You must be signed in to change notification settings - Fork 0
/
gift1.cpp
69 lines (51 loc) · 1.24 KB
/
gift1.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
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
ID: cl34nc0d3r
LANG: C++
TASK: gift1
*/
#include <string>
#include <vector>
#include <fstream>
#include <unordered_map>
using namespace std;
int main()
{
ofstream fout("gift1.out");
ifstream fin("gift1.in");
unordered_map<string, int> givers;
vector<string> giver_names;
int num_of_givers;
string recipient_name;
string giver_name;
string line;
fin >> num_of_givers;
int amount;
int num_of_recipients;
for (int i = 0; i < num_of_givers; i++)
{
fin >> giver_name;
giver_names.push_back(giver_name);
givers[giver_name] = 0;
}
while (true)
{
if (!(fin >> giver_name))
break;
fin >> amount >> num_of_recipients;
if (amount == 0)
continue;
int rem = amount % num_of_recipients;
int gift = amount / num_of_recipients;
givers[giver_name] += rem - amount;
for (int i = 0; i < num_of_recipients; i++)
{
fin >> recipient_name;
givers[recipient_name] += gift;
}
}
for (auto &name : giver_names)
{
fout << name << ' ' << givers[name] << endl;
}
return 0;
}