-
Notifications
You must be signed in to change notification settings - Fork 0
/
buckets.cpp
87 lines (80 loc) · 2.04 KB
/
buckets.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//The Bucket Brigade
//By: Max Yang
//Time: 1 hour
//In my program, the only program I couldn't find was that I couldn't transfer the characters into the array since an array kept coming
#include <cstdlib>
#include <string>
int main(){
FILE * In = fopen("buckets.in", "r");
int barn_x, barn_y, rock_x, rock_y, lake_x, lake_y;
for (int i = 1; i<=10; i++){
char k[1];
fscanf(In, "%c", char(k[i])); //Not transferring character correctly?
for(int j = 1; j<=10; j++){
if (k[j] == 'B') {
barn_x = i;
barn_y = j;
}
if (k[j] == 'R') {
rock_x = i;
rock_y = j;
}
if (k[j] == 'L') {
lake_x = i;
lake_y = i;
}
}
}
fclose (In);
printf("barn: (%c, %c)", barn_x, barn_y); //check coordinate
int ans;
if (barn_x == rock_x == lake_x){ //#1
ans = abs((lake_y-barn_y)+(lake_x-barn_x))+2;
}else if (barn_y == rock_y == lake_y){ //#2
ans = abs((lake_y-barn_y)+(lake_x-barn_x))+1;
}else{ //#3
ans = abs((lake_y-barn_y)+(lake_x-barn_x)); }
FILE * Out = fopen("buckets.out", "w");
fscanf(Out, "%d", ans);
fclose(Out);
/*
#1
..........
..........
.......BC. B at (8, 3)
.......RC. R at (8, 4)
.......CC.
.......L.. L at (8, 5)
..........
..........
..........
..........
8-8 + 5-3 = 2 + 2 = 4
*/
/*
#2
..........
....CCC...
..BCCRCCL. B at (3, 3); R at (6, 3); L at (9, 3)
..........
..........
..........
..........
..........
..........
..........
3-3 + 9-3 = 6 + 1 = 7
*/
/*
#3
..........
..........
..B....... B at (3, 4)
..C...R... R at (7, 5)
..C.......
..CCCCCCCL L at (10, 6)
..........
..........
..........
10-3 + 6-4 = 9
*/