-
Notifications
You must be signed in to change notification settings - Fork 0
/
119 - Greedy Gift Givers.cpp
64 lines (56 loc) · 1.43 KB
/
119 - Greedy Gift Givers.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
#include<iostream>
#include<string>
using namespace std;
int main()
{
int N, flag = 0;
while(cin>>N)
{
string name[N];
int dollar[N];
for(int i=0; i<N; i++)
{
cin>>name[i];
dollar[i] = 0;
}
string getName;
int spend, numberPerson, money;
int i, j, k;
for( k=0; k<N; k++)
{
cin>>getName;
cin>>spend;
for( i=0; i<N; i++)
if(getName == name[i])
{
dollar[i] -= spend;
break;
}
cin>>numberPerson;
if(numberPerson == 0)
{
dollar[i] += spend;
continue;
}
if(spend%numberPerson != 0)
dollar[i] += spend%numberPerson;
string gotGift[numberPerson];
for( i=0; i<numberPerson; i++)
{
cin>>gotGift[i];
for( j=0; j<N; j++)
if(gotGift[i] == name[j])
{
dollar[j] += (spend/numberPerson);
break;
}
}
}
if(flag == 1)
cout<<endl;
flag = 1;
for( i=0; i<N; i++)
cout<<name[i]<<" "<<dollar[i]<<endl;
}
return 0;
}