-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.cpp
58 lines (48 loc) · 1.13 KB
/
solution.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
#include <cstdio>
#include <cstring>
char tName[15][15];
int tm;
int stringCompare(char *p)
{
int i;
for(i = 0; i < tm; i++) {
if(strcmp(p, tName[i]) == 0)
break;
}
return i;
}
int main()
{
int m, pm, p;
int tMoney[15];
char pName[15];
int a = 0;
while(scanf("%d", &tm) == 1) {
if(a != 0)
printf("\n");
a = 1;
for(int i = 0; i < tm; i++) {
scanf("%s", tName[i]);
tMoney[i] = 0;
}
for(int i = 0; i < tm; i++) {
scanf("%s %d %d", pName, &m, &pm);
p = stringCompare(pName);
tMoney[p] = tMoney[p] - m;
if(pm != 0) {
tMoney[p] = tMoney[p] + (m - (m / pm) * pm);
} else {
tMoney[p] = tMoney[p] + m;
}
for(int j = 1; j <= pm; j++) {
scanf("%s", pName);
p = stringCompare(pName);
tMoney[p] = tMoney[p] + (m / pm);
}
}
for(int i = 0; i < tm; i++) {
printf("%s %d\n", tName[i], tMoney[i]);
}
}
return 0;
}