Advertisement
Guest User

d

a guest
Mar 27th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.  
  7. int plansza [10][10] = {
  8. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  9. {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  10. {1, 0, 1, 1, 1, 1, 1, 1, 0, 1},
  11. {1, 0, 1, 0, 0, 0, 0, 0, 0, 1},
  12. {1, 0, 1, 0, 1, 1, 1, 1, 0, 1},
  13. {1, 0, 1, 0, 1, 2, 1, 1, 0, 1},
  14. {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
  15. {1, 0, 1, 0, 1, 0, 1, 1, 0, 1},
  16. {1, 8, 1, 0, 0, 0, 1, 0, 0, 1},
  17. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  18. };
  19.  
  20. int d=0; // dlugosc tablicy z wynikami
  21. int sciezka [2][d] ; // tablica ze sciezka, ktora przebyl pionek
  22. int i,j; // zmienne pomocnicze
  23. int x=8; // wspolrzedna x
  24. int y=1; // wspolrzedna y
  25. int p;
  26.  
  27. printf("Oto twoja plansza, liczba 8 oznacza miejsce startu, liczba 2 - koniec\n\n");
  28. printf(" 1 2 3 4 5 6 7 8 9 10\n");
  29.  
  30. for(i=0; i<10; i++)
  31. {
  32.  
  33. printf("\n");
  34. if (i==9)
  35. printf("%d ",i+1);
  36. else
  37. printf("%d ",i+1);
  38.  
  39. for(j=0; j<10; j++)
  40. printf ("%d ", plansza[i][j]);
  41.  
  42. }
  43.  
  44. printf ("\n \n");
  45.  
  46. // czesc wypisujaca
  47.  
  48.  
  49. do
  50. {
  51. if (plansza[x-1][y] == 0)
  52. {
  53.  
  54. sciezka[0][d++] = x;
  55. sciezka[1][d++] = y;
  56. plansza[x][y] = 1;
  57. x--;
  58.  
  59.  
  60. }
  61. else
  62. {
  63. if (plansza[x][y+1] == 0)
  64. {
  65.  
  66. sciezka[0][d++] = x;
  67. sciezka[1][d++] = y;
  68. plansza[x][y] = 1;
  69. y++;
  70.  
  71.  
  72. }
  73. else
  74. {
  75. if (plansza[x+1][y] == 0)
  76. {
  77.  
  78. sciezka[0][d++] = x;
  79. sciezka[1][d++] = y;
  80. plansza[x][y] = 1;
  81. x++;
  82.  
  83.  
  84. }
  85. else
  86. {
  87. if (plansza[x][y-1] == 0)
  88. {
  89.  
  90.  
  91. sciezka[0][d++] = x;
  92. sciezka[1][d++] = y;
  93. plansza[x][y] = 1;
  94. y--;
  95.  
  96.  
  97. }
  98. else
  99. {
  100. plansza[x][y] = 1;
  101. x = sciezka[0][d--];
  102. y = sciezka[1][d--];
  103. d--;
  104.  
  105. }
  106. }
  107. }
  108. }
  109.  
  110.  
  111. }
  112. while (plansza[x][y] != 2);
  113.  
  114.  
  115. printf("Nasza sciezka:\n");
  116. for(i=1; i<d; i++)
  117. printf("X: %d, Y:%d ;\n", sciezka[0][d],sciezka[1][d]);
  118.  
  119.  
  120. return 0;
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement