-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask03-gift1.c
60 lines (52 loc) · 852 Bytes
/
task03-gift1.c
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
/*
ID: zltsang1
LANG: C
TASK: gift1
*/
#include <stdio.h>
int np;
char gp[10][15];
int ini[10];
int lef[10];
int gm[10][10];
int n2i(const char *s){
int i;
for(i=0;i<np;i++){
if(!strcmp(gp[i],s))return i;
}
return -1;
}
main () {
FILE *fin = fopen ("gift1.in", "r");
FILE *fout = fopen ("gift1.out", "w");
int i,t,c,a,b,j;
char na[15];
fscanf (fin, "%d", &np);
for(i=0;i<np;i++){
fscanf(fin, "%s", gp[i]);
}
for(i=0;i<np;i++){
fscanf(fin, "%s", na);
t=n2i(na);
fscanf(fin, "%d %d", ini+t, &c);
if(!c){
lef[t]=ini[t];
continue;
}
a=ini[t]/c;
lef[t]=ini[t]%c;
for(j=0;j<c;j++){
fscanf(fin, "%s", na);
b=n2i(na);
gm[t][b]=a;
}
}
for(i=0;i<np;i++){
for(j=0;j<np;j++)
lef[i]+=gm[j][i];
}
for(i=0;i<np;i++){
fprintf (fout, "%s %d\n", gp[i], lef[i]-ini[i]);
}
exit (0);
}