Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.89 KB | None | 0 0
  1. char znaki[10][10];
  2. char droga[10][10];
  3. using namespace std;
  4.  
  5. bool re(int sx, int sy, int kx, int ky)
  6. {
  7.     int bok=10;
  8.  
  9.     if((sx-1==kx&&sy==ky)||(sx==kx&&sy-1==ky)||(sx==kx&&sy+1==ky)||(sx+1==kx&&sy==ky))
  10.         return true;
  11.  
  12.     if(((sx<=0)||(droga[sx-1][sy]=='x'||droga[sx-1][sy]=='#'||droga[sx-1][sy]=='.'))&&
  13.             ((sx>=bok-1)||(droga[sx+1][sy]=='x'||droga[sx+1][sy]=='.'||droga[sx+1][sy]=='#'))
  14.             &&((sy<=0)||(droga[sx][sy-1]=='.'||droga[sx][sy-1]=='x'||droga[sx][sy-1]=='#'))
  15.             &&((sy>=bok-1)||(droga[sx][sy+1]=='.'||droga[sx][sy+1]=='x'||droga[sx][sy+1]=='#')))
  16.     {
  17.         droga[sx][sy]='x';
  18.         if(sx<bok-1&&droga[sx+1][sy]=='.')
  19.             re(sx+1, sy, kx, ky);
  20.  
  21.         if(sy<bok-1&&droga[sx][sy+1]=='.')
  22.             re(sx, sy+1, kx, ky);
  23.  
  24.         if(sy>0&&droga[sx][sy-1]=='.')
  25.             re(sx, sy-1, kx, ky);
  26.  
  27.         if(sx>0&&droga[sx-1][sy]=='.')
  28.             re(sx-1, sy, kx, ky);
  29.     }
  30.  
  31.     if(sx<bok-1&&droga[sx+1][sy]==' ')
  32.     {
  33.         droga[sx+1][sy]='.';
  34.         cout<<endl<<sx+1<<" "<<sy;
  35.         cout<<endl;
  36.         for(int i=0; i<bok; i++)
  37.         {
  38.             for(int j=0; j<bok; j++)
  39.             {
  40.                 if(droga[i][j]=='x')
  41.                 {
  42.                     cout<<' ';
  43.                 }
  44.                 else
  45.                 {
  46.                     cout<<droga[i][j];
  47.                 }
  48.             }
  49.             cout<<endl;
  50.         }
  51.         re(sx+1, sy, kx, ky);
  52.     }
  53.     if(sy<bok-1&&droga[sx][sy+1]==' ')
  54.     {
  55.         droga[sx][sy+1]='.';
  56.         cout<<endl<<sx<<" "<<sy+1;
  57.         cout<<endl;
  58.         for(int i=0; i<bok; i++)
  59.         {
  60.             for(int j=0; j<bok; j++)
  61.             {
  62.                 if(droga[i][j]=='x')
  63.                 {
  64.                     cout<<' ';
  65.                 }
  66.                 else
  67.                 {
  68.                     cout<<droga[i][j];
  69.                 }
  70.             }
  71.             cout<<endl;
  72.         }
  73.         re(sx, sy+1, kx, ky);
  74.     }
  75.     if(sy>0&&droga[sx][sy-1]==' ')
  76.     {
  77.         droga[sx][sy-1]='.';
  78.         cout<<endl<<sx<<" "<<sy-1;
  79.         cout<<endl;
  80.         for(int i=0; i<bok; i++)
  81.         {
  82.             for(int j=0; j<bok; j++)
  83.             {
  84.                 if(droga[i][j]=='x')
  85.                 {
  86.                     cout<<' ';
  87.                 }
  88.                 else
  89.                 {
  90.                     cout<<droga[i][j];
  91.                 }
  92.             }
  93.             cout<<endl;
  94.         }
  95.         re(sx, sy-1, kx, ky);
  96.     }
  97.     if(sx>0&&droga[sx-1][sy]==' ')
  98.     {
  99.         droga[sx-1][sy]='.';
  100.         cout<<endl<<sx-1<<" "<<sy;
  101.         cout<<endl;
  102.         for(int i=0; i<bok; i++)
  103.         {
  104.             for(int j=0; j<bok; j++)
  105.             {
  106.                 if(droga[i][j]=='x')
  107.                 {
  108.                     cout<<' ';
  109.                 }
  110.                 else
  111.                 {
  112.                     cout<<droga[i][j];
  113.                 }
  114.             }
  115.             cout<<endl;
  116.         }
  117.         re(sx-1, sy, kx, ky);
  118.     }
  119. }
  120.  
  121. main()
  122. {
  123.     ifstream dane;
  124.     dane.open("lab.txt");
  125.     int bok;
  126.     dane>>bok;
  127.     char znaki[bok][bok];
  128.     int y_st, x_st, y_end, x_end;
  129.     string wczyt;
  130.     getline(dane,wczyt);
  131.     wczyt="";
  132.     for(int i=0; i<bok; i++)
  133.     {
  134.         getline(dane,wczyt);
  135.         for(int n=0; n<bok; n++)
  136.             znaki[i][n]=wczyt[n];
  137.  
  138.         wczyt="";
  139.  
  140.     }
  141.  
  142.     for(int i=0; i<bok; i++)
  143.     {
  144.         cout<<endl;
  145.         for(int n=0; n<bok; n++)
  146.         {
  147.             cout<<znaki[i][n];
  148.             if(znaki[i][n]=='A')
  149.                 x_st=n, y_st=i;
  150.             if(znaki[i][n]=='B')
  151.                 x_end=n, y_end=i;
  152.  
  153.         }
  154.  
  155.     }
  156.     //cout<<endl<<x_st<<endl<<y_st<<endl<<x_end<<endl<<y_end<<endl;
  157.     for(int i=0; i<bok; i++)
  158.     {
  159.         for(int j=0; j<bok; j++) droga[i][j]=znaki[i][j];
  160.     }
  161.  
  162.     re(y_st, x_st, y_end, x_end);
  163.     cout<<endl;
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement