#include <stdio.h>
#include <stdlib.h>
void print_position(int x, int y);
void print_maze(char **maze, int largura, int altura);
int labirinto(int x_atual, int y_atual, char **maze, int largura, int altura) {
int imaior = x_atual;
int imenor = x_atual;
int ybaixo = y_atual;
int ycima = y_atual;
while (imaior < largura - 1) {
if (maze[x_atual + 1][y_atual] != 'X' && maze[x_atual + 1][y_atual] != 'P') {
maze[x_atual][y_atual] = 'P';
x_atual += 1;
}
imaior++;
}
while (imenor > 0) {
if (maze[x_atual - 1][y_atual] != 'X' && maze[x_atual - 1][y_atual] != 'P') {
maze[x_atual][y_atual] = 'P';
x_atual -= 1;
}
imenor--;
}
while (ycima > 0) {
if (maze[x_atual][y_atual - 1] != 'X' && maze[x_atual][y_atual - 1] != 'P') {
maze[x_atual][y_atual] = 'P';
y_atual -= 1;
}
ycima--;
}
while (ybaixo < altura - 1) {
if (maze[x_atual][y_atual + 1] != 'X' && maze[x_atual][y_atual + 1] != 'P') {
maze[x_atual][y_atual] = 'P';
y_atual += 1;
}
ybaixo++;
}
maze = labirinto(x_atual, y_atual, maze, largura, altura);
}
int main(void) {
int largura, altura, x_saida, y_saida, x, y;
scanf("%d %d\n", &largura
, &altura
); char **a
= malloc(largura
* sizeof(char*)); for (x = 0; x < largura; x++) {
a
[x
] = malloc(altura
* sizeof(char)); }
for (y = altura - 1; y >= 0; y--) {
for (x = 0; x < largura; x++) {
if (a[x][y] == 'S') {
x_saida = x;
y_saida = y;
}
}
getchar(); //pegar a quebra de linha }
print_maze(a, largura, altura);
//eu acredito que seja mais facil comecar a busca pela saida
labirinto(x_saida, y_saida, a, largura, altura);
return 0;
}
void print_maze(char **maze, int largura, int altura) {
int x, y;
for (y = altura - 1; y >= 0; y--) {
for (x = 0; x < largura; x++) {
}
}
}
void print_position(int x, int y) {
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCnZvaWQgcHJpbnRfcG9zaXRpb24oaW50IHgsIGludCB5KTsKCnZvaWQgc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HVhbCAtPSAxOwogICAgICAgIH0KICAgICAgICB5Y2ltYS0tOwogICAgfQoKICAgIHdoaWxlICh5YmFpeG8gPCBhbHR1cmEgLSAxKSB7CiAgICAgICAgaWYgKG1hemVbeF9hdHVhbF1beV9hdHVhbCArIDFdICE9ICdYJyAmJiBtYXplW3hfYXR1YWxdW3lfYXR1YWwgKyAxXSAhPSAnUCcpIHsKICAgICAgICAgICAgbWF6ZVt4X2F0dWFsXVt5X2F0dWFsXSA9ICdQJzsKICAgICAgICAgICAgeV9hdHVhbCArPSAxOwogICAgICAgIH0KICAgICAgICB5YmFpeG8rKzsKICAgIH0KCiAgICBtYXplID0gbGFiaXJpbnRvKHhfYXR1YWwsIHlfYXR1YWwsIG1hemUsIGxhcmd1cmEsIGFsdHVyYSk7Cn0KCmludCBtYWluKHZvaWQpIHsKICAgIGludCBsYXJndXJhLCBhbHR1cmEsIHhfc2FpZGEsIHlfc2FpZGEsIHgsIHk7CiAgICBzY2FuZigiJWQgJWRcbiIsICZsYXJndXJhLCAmYWx0dXJhKTsKICAgIGNoYXIgKiphID0gbWFsbG9jKGxhcmd1cmEgKiBzaXplb2YoY2hhciopKTsKICAgIGZvciAoeCA9IDA7IHggPCBsYXJndXJhOyB4KyspIHsKICAgICAgICBhW3hdID0gbWFsbG9jKGFsdHVyYSAqIHNpemVvZihjaGFyKSk7CiAgICB9CiAgICBmb3IgKHkgPSBhbHR1cmEgLSAxOyB5ID49IDA7IHktLSkgewogICAgICAgIGZvciAoeCA9IDA7IHggPCBsYXJndXJhOyB4KyspIHsKICAgICAgICAgICAgYVt4XVt5XSA9IGdldGNoYXIoKTsKICAgICAgICAgICAgaWYgKGFbeF1beV0gPT0gJ1MnKSB7CiAgICAgICAgICAgICAgICB4X3NhaWRhID0geDsKICAgICAgICAgICAgICAgIHlfc2FpZGEgPSB5OwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldGNoYXIoKTsgLy9wZWdhciBhIHF1ZWJyYSBkZSBsaW5oYQogICAgfQogICAgcHJpbnRfbWF6ZShhLCBsYXJndXJhLCBhbHR1cmEpOwogICAgLy9ldSBhY3JlZGl0byBxdWUgc2VqYSBtYWlzIGZhY2lsIGNvbWVjYXIgYSBidXNjYSBwZWxhIHNhaWRhCiAgICBsYWJpcmludG8oeF9zYWlkYSwgeV9zYWlkYSwgYSwgbGFyZ3VyYSwgYWx0dXJhKTsKICAgIHByaW50ZigiXG4iKTsKICAgIHJldHVybiAwOwp9Cgp2b2lkIHByaW50X21hemUoY2hhciAqKm1hemUsIGludCBsYXJndXJhLCBpbnQgYWx0dXJhKSB7CiAgICBpbnQgeCwgeTsKICAgIGZvciAoeSA9IGFsdHVyYSAtIDE7IHkgPj0gMDsgeS0tKSB7CiAgICAgICAgZm9yICh4ID0gMDsgeCA8IGxhcmd1cmE7IHgrKykgewogICAgICAgICAgICBwcmludGYoIiVjIiwgbWF6ZVt4XVt5XSk7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiXG4iKTsKICAgIH0KfQoKdm9pZCBwcmludF9wb3NpdGlvbihpbnQgeCwgaW50IHkpIHsKICAgIHByaW50ZigiKCVkLCAlZCkiLCB4LCB5KTsKfQ==