-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA119.cpp
More file actions
74 lines (62 loc) · 1.32 KB
/
Copy pathUVA119.cpp
File metadata and controls
74 lines (62 loc) · 1.32 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
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <string.h>
#include <vector>
#define MAXPEOPLE 10
#define NAMELEN 32
using namespace std;
typedef struct Person Person;
struct Person {
char name[NAMELEN];
int total =0;
};
vector<Person> people;
int npeople;
void
addperson(char *name)
{
Person temp;
strcpy(temp.name, name);
people.push_back(temp);
npeople++;
}
Person* lookup(char *name)
{
int i;
for(i=0; i<npeople; i++){
if(strcmp(name, people[i].name) == 0){
return &people[i];
}
}
}
int main()
{
char name[NAMELEN];
int i, j, np, amt, ng;
Person *giver, *receiver;
int counter =0;
while(scanf("%d", &np) != EOF){
if(counter){
printf("\n");
}
people.clear();
for(i=0; i<np; i++) {
scanf("%s", name);
addperson(name);
}
for(i=0; i<np; i++) {
scanf("%s %d %d", name, &amt, &ng);
giver = lookup(name);
for(j=0; j<ng; j++) {
scanf("%s", name);
receiver = lookup(name);
giver->total -= amt/ng;
receiver->total += amt/ng;
}
}
for(i=0; i<np; i++){
printf("%s %d\n", people[i].name, people[i].total);
}
counter++;
}
return 0;
}