Advertisement
it4l0

labirinto

Dec 15th, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.      int linhas = 0, colunas = 0, cont = 0, xinicial = 0, yinicial = 0, x = 0, y = 0, l = 0, c = 0, i = 0;
  5.      scanf("%d%d", &linhas, &colunas); int labirinto [linhas][colunas];
  6.      char mov;
  7.      for (l = 0; l < linhas; l++)
  8.      {
  9.           for (c = 0; c < colunas; c++)
  10.           {
  11.                scanf("%d", &labirinto[l][c]);
  12.           }
  13.      }
  14.      scanf("%d", &cont); char movimento [cont];
  15.      for(i = 0; i < cont; i++)
  16.      {
  17.           scanf(" %c", &movimento[i]);
  18.      }
  19.      scanf("%d %d", &xinicial, &yinicial); x = xinicial; y = yinicial;
  20.      for (i = 0; i < cont; i++)
  21.      {
  22.           if(movimento[i] == 'C')
  23.           {
  24.                if (labirinto[xinicial - 1][yinicial] == 1)
  25.                {
  26.                     x--; xinicial--;
  27.                }
  28.           }
  29.           else if(movimento[i] == 'B')
  30.           {
  31.                if (labirinto[xinicial + 1][yinicial] == 1)
  32.                {
  33.                     x++; xinicial++;
  34.                }
  35.           }
  36.           else if(movimento[i] == 'D')
  37.           {
  38.                if (labirinto[xinicial][yinicial + 1] == 1)
  39.                {
  40.                     y++; yinicial++;
  41.                }
  42.           }
  43.           else if(movimento[i] == 'E')
  44.           {
  45.                if (labirinto[xinicial][yinicial - 1] == 1)
  46.                {
  47.                     y--; yinicial--;
  48.                }
  49.                
  50.           }
  51.      }
  52.      printf("(%d,%d)", x, y);
  53.      return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement