Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int linhas = 0, colunas = 0, cont = 0, xinicial = 0, yinicial = 0, x = 0, y = 0, l = 0, c = 0, i = 0;
- scanf("%d%d", &linhas, &colunas); int labirinto [linhas][colunas];
- char mov;
- for (l = 0; l < linhas; l++)
- {
- for (c = 0; c < colunas; c++)
- {
- scanf("%d", &labirinto[l][c]);
- }
- }
- scanf("%d", &cont); char movimento [cont];
- for(i = 0; i < cont; i++)
- {
- scanf(" %c", &movimento[i]);
- }
- scanf("%d %d", &xinicial, &yinicial); x = xinicial; y = yinicial;
- for (i = 0; i < cont; i++)
- {
- if(movimento[i] == 'C')
- {
- if (labirinto[xinicial - 1][yinicial] == 1)
- {
- x--; xinicial--;
- }
- }
- else if(movimento[i] == 'B')
- {
- if (labirinto[xinicial + 1][yinicial] == 1)
- {
- x++; xinicial++;
- }
- }
- else if(movimento[i] == 'D')
- {
- if (labirinto[xinicial][yinicial + 1] == 1)
- {
- y++; yinicial++;
- }
- }
- else if(movimento[i] == 'E')
- {
- if (labirinto[xinicial][yinicial - 1] == 1)
- {
- y--; yinicial--;
- }
- }
- }
- printf("(%d,%d)", x, y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement