-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUAS#2_Labyrinth.cpp
More file actions
71 lines (61 loc) · 1.14 KB
/
UAS#2_Labyrinth.cpp
File metadata and controls
71 lines (61 loc) · 1.14 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
#include<stdio.h>
int x1, y1;
int x2, y2;
char map[12][12];
int berhasil;
void floodfill(int posX, int posY){
if(posX < 0 || posY < 0 || posX > 9 || posY > 9 || map[posX][posY] == '\n' || map[posX][posY] == '\0' || map[posX][posY] == '#'){
return;
}
if(map[posX][posY] == 'E'){
berhasil = 1;
}
map[posX][posY] = '#';
floodfill(posX + 1, posY);
floodfill(posX - 1, posY);
floodfill(posX, posY + 1);
floodfill(posX, posY - 1);
}
int main(){
for(int i = 0; i < 10; i++){
for(int j = 0; j < 11; j++){
scanf("%c", &map[i][j]);
if(map[i][j] == 'S'){
x1 = i;
y1 = j;
}
}
}
floodfill(x1, y1);
if(berhasil == 1){
printf("BERHASIL\n");
} else{
printf("GAGAL\n");
}
// for(int i = 0; i < 10; i++){
// for(int j = 0; j < 11; j++){
// printf("%c", map[i][j]);
// }
// }
return 0;
}
//#S########
//# ## ##
//# ## ## ##
//# ##
//# # ### ##
//# # ### ##
//# # ### ##
//# # ##
//# ##### ##
//#E ##
//##########
//#### ##
//#### ## ##
//#S ##
//### ### ##
//### ### ##
//### ######
//#### E#
//##########
//##########