-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobo.c
54 lines (43 loc) · 1.2 KB
/
Robo.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
#include <stdio.h>
int ehValido(int x, int y, int L, int C, int mapa[L][C]) {
return x >= 0 && x < L && y >= 0 && y < C && mapa[x][y] == 1;
}
void encontrarPosicaoFinal(int L, int C, int startX, int startY, int mapa[L][C], int *finalX, int *finalY) {
int x = startX - 1;
int y = startY - 1;
while (1) {
if (ehValido(x - 1, y, L, C, mapa)) {
mapa[x][y] = 0;
x--;
} else if (ehValido(x + 1, y, L, C, mapa)) {
mapa[x][y] = 0;
x++;
} else if (ehValido(x, y - 1, L, C, mapa)) {
mapa[x][y] = 0;
y--;
} else if (ehValido(x, y + 1, L, C, mapa)) {
mapa[x][y] = 0;
y++;
} else {
break;
}
}
*finalX = x + 1;
*finalY = y + 1;
}
int main() {
int L, C;
scanf("%d %d", &L, &C);
int A, B;
scanf("%d %d", &A, &B);
int mapa[L][C];
for (int i = 0; i < L; i++) {
for (int j = 0; j < C; j++) {
scanf("%d", &mapa[i][j]);
}
}
int finalX, finalY;
encontrarPosicaoFinal(L, C, A, B, mapa, &finalX, &finalY);
printf("%d %d\n", finalX, finalY);
return 0;
}