Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. int main()
  7. {
  8. int linha, coluna, c1, c2, quantmov, contador, li, ci;
  9. scanf("%i %i", &linha, &coluna);
  10. int matriz[linha][coluna];
  11.  
  12. for(c1 = 0 ; c1 < linha ; ++c1)
  13. {
  14. for (c2 = 0; c2 < coluna ; ++c2)
  15. {
  16. scanf("%i", &matriz[linha][coluna]);
  17. }
  18. }
  19.  
  20. scanf("%i", &quantmov);
  21. quantmov - 1;
  22. int mov[quantmov];
  23.  
  24. char movimento;
  25. contador = quantmov;
  26. while (contador >= 0)
  27. {
  28. scanf("%c", &movimento);
  29. printf("%c", movimento);
  30. if(movimento == 'C')
  31. {
  32. mov[contador] = 1;
  33. }
  34. if(movimento == 'D')
  35. {
  36. mov[contador] = 2;
  37. }
  38. if(movimento == 'B')
  39. {
  40. mov[contador] = 3;
  41. }
  42. if(movimento == 'E')
  43. {
  44. mov[contador] = 4;
  45. }
  46. --contador;
  47. }
  48.  
  49. scanf("%i%i", &li, &ci);
  50. contador = quantmov;
  51. while (contador >= 0)
  52. {
  53.  
  54. if(mov[contador] == 1 && matriz[li + 1][ci] == 1)
  55. {
  56. li+=1;
  57. }
  58. else if(mov[contador] == 2 && matriz[li][ci + 1] == 1)
  59. {
  60. ci += 1;
  61. }
  62. else if(mov[contador] == 3 && matriz[li - 1][ci] == 1)
  63. {
  64. li -= 1;
  65. }
  66. else if(mov[contador] == 4 && matriz[li][ci - 1] == 1)
  67. {
  68. ci -= 1;
  69. }
  70. --contador;
  71. }
  72.  
  73. printf("(%i,%i)\n", ci, li);
  74.  
  75. return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement