# Domači

a guest
Nov 11th, 2014
119
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2.
3. #define red 7
4. #define kolona 7
5.
6. /*
7. *   Simboli:
8. *   '0' = Slobodna polja
9. *   '1' = Zidovi
10. *   'P' = Pocetak
11. *   'K' = Kraj
12. *   '+' = Put
13. */
14. char lavirint[red][kolona] = {
15.     "100111",
16.     "101110",
17.     "101000",
18.     "100010",
19.     "111110",
20.     "111000"
21. };
22.
23. void ispisiLavirint(void){
24.     printf("Lavirint:\n");
25.     for(int i = 0; i < red; i++) printf("%.*s\n", kolona, lavirint[i]);
26.     printf("\n");
27.     return;
28. }
29.
30. int nadjiPut(int y, int x){
31.     if( x < 0 || x > kolona - 1 || y < 0 || y > red - 1) return 0;
32.     if(lavirint[y][x] == 'K' ) return 1;
33.     if(lavirint[y][x] != '0' && lavirint[y][x] != 'P') return 0;
34.     lavirint[y][x] = '+';
35.     if(nadjiPut(y, x - 1) == 1) return 1;
36.     if(nadjiPut(y + 1, x) == 1) return 1;
37.     if(nadjiPut(y, x + 1) == 1) return 1;
38.     if(nadjiPut(y - 1, x) == 1) return 1;
39.     lavirint[y][x] = '0';
40.     return 0;
41. }
42.
43. int main(void){
44.     int xp, yp, xk, yk;
45.     printf("Unesite koordinate pocetne tacke x y: ");
46.     scanf("%d %d", &yp, &xp);
47.     lavirint[yp][xp] = 'P';
48.     printf("Unesite koordinate krajnje tacke x y: ");
49.     scanf("%d %d", &yk, &xk);
50.     lavirint[yk][xk] = 'K';
51.
52.     ispisiLavirint();
53.