Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
- void mark(int **M, ,int x, int y){
- if (M[x][y] == -1) return; //se for -1, nΓ£o marca
- for (int d = 0; d < 4; ++d) {
- int nx = x + dir[d][0]; //esq e dir (pegar o termo 0 das chaves)
- int ny = y + dir[d][1]; //cima e baixo (pegar o termo 1 das chaves)
- if (nx < 0 || ny < 0 || nx >= tam || ny >= tam) continue;
- if (M[nx][ny] > M[x][y]+1 || M[nx][ny] == 0){
- M[nx][ny] = M[x][y] + 1;
- }
- mark(**M, nx, ny);
- }
- }
- int main(void){
- int tam,i,j, poss;
- printf("Digite o tamanho da matriz:\n");
- scanf("%d", &tam);
- int M[tam][tam];
- for(int i=0;i<tam;i++){
- for(int j=0;j<tam;j++){
- scanf("%d", &M[i][j]);
- }
- }
- printf("Digite as coordenadas de B\n");
- scanf("%d %d", &i, &j);
- M[i][j] = 1;
- mark(x,y)
- printf("Digite as coordenadas de A\n");
- scanf("%d %d", &i, &j);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement