Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. bool rat_walk(bool maze[4][4] , int pos_x , int pos_y , bool track[4][4])
  7. {
  8.  
  9.     if(pos_x == 3 && pos_y == 3)
  10.     {
  11.         return true;
  12.     }
  13.  
  14.     if(maze[pos_y][pos_x] == 0)
  15.         return false;
  16.  
  17.     if(rat_walk(maze,pos_x+1,pos_y,track))
  18.     {
  19.         track[pos_y][pos_x+1] = 1;
  20.     }else if(rat_walk(maze,pos_x,pos_y+1,track))
  21.     {
  22.         track[pos_y+1][pos_x] = 1;
  23.     }
  24. }
  25.  
  26. int main()
  27. {
  28.     ifstream in("maze.txt");
  29.     bool maze[4][4];
  30.     bool track[4][4] = {0};
  31.     track[0][0] = 1;
  32.  
  33.     for(int i = 0 ; i < 4 ; i++){
  34.         for(int k = 0 ; k < 4 ; k++){
  35.             in >> maze[i][k];
  36.         }
  37.     }
  38.  
  39.     if(rat_walk(maze,0,0,track)){
  40.         for(int i = 0 ; i < 4 ; i++){
  41.         for(int k = 0 ; k < 4 ; k++){
  42.             cout << track[i][k] << "  ";
  43.         }
  44.         cout << endl;
  45.     }
  46.     }else{
  47.         cout << "nincs ut";
  48.     }
  49.  
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement