Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char znaki[10][10];
- char droga[10][10];
- using namespace std;
- bool re(int sx, int sy, int kx, int ky)
- {
- int bok=10;
- if((sx-1==kx&&sy==ky)||(sx==kx&&sy-1==ky)||(sx==kx&&sy+1==ky)||(sx+1==kx&&sy==ky))
- return true;
- if(((sx<=0)||(droga[sx-1][sy]=='x'||droga[sx-1][sy]=='#'||droga[sx-1][sy]=='.'))&&
- ((sx>=bok-1)||(droga[sx+1][sy]=='x'||droga[sx+1][sy]=='.'||droga[sx+1][sy]=='#'))
- &&((sy<=0)||(droga[sx][sy-1]=='.'||droga[sx][sy-1]=='x'||droga[sx][sy-1]=='#'))
- &&((sy>=bok-1)||(droga[sx][sy+1]=='.'||droga[sx][sy+1]=='x'||droga[sx][sy+1]=='#')))
- {
- droga[sx][sy]='x';
- if(sx<bok-1&&droga[sx+1][sy]=='.')
- re(sx+1, sy, kx, ky);
- if(sy<bok-1&&droga[sx][sy+1]=='.')
- re(sx, sy+1, kx, ky);
- if(sy>0&&droga[sx][sy-1]=='.')
- re(sx, sy-1, kx, ky);
- if(sx>0&&droga[sx-1][sy]=='.')
- re(sx-1, sy, kx, ky);
- }
- if(sx<bok-1&&droga[sx+1][sy]==' ')
- {
- droga[sx+1][sy]='.';
- cout<<endl<<sx+1<<" "<<sy;
- cout<<endl;
- for(int i=0; i<bok; i++)
- {
- for(int j=0; j<bok; j++)
- {
- if(droga[i][j]=='x')
- {
- cout<<' ';
- }
- else
- {
- cout<<droga[i][j];
- }
- }
- cout<<endl;
- }
- re(sx+1, sy, kx, ky);
- }
- if(sy<bok-1&&droga[sx][sy+1]==' ')
- {
- droga[sx][sy+1]='.';
- cout<<endl<<sx<<" "<<sy+1;
- cout<<endl;
- for(int i=0; i<bok; i++)
- {
- for(int j=0; j<bok; j++)
- {
- if(droga[i][j]=='x')
- {
- cout<<' ';
- }
- else
- {
- cout<<droga[i][j];
- }
- }
- cout<<endl;
- }
- re(sx, sy+1, kx, ky);
- }
- if(sy>0&&droga[sx][sy-1]==' ')
- {
- droga[sx][sy-1]='.';
- cout<<endl<<sx<<" "<<sy-1;
- cout<<endl;
- for(int i=0; i<bok; i++)
- {
- for(int j=0; j<bok; j++)
- {
- if(droga[i][j]=='x')
- {
- cout<<' ';
- }
- else
- {
- cout<<droga[i][j];
- }
- }
- cout<<endl;
- }
- re(sx, sy-1, kx, ky);
- }
- if(sx>0&&droga[sx-1][sy]==' ')
- {
- droga[sx-1][sy]='.';
- cout<<endl<<sx-1<<" "<<sy;
- cout<<endl;
- for(int i=0; i<bok; i++)
- {
- for(int j=0; j<bok; j++)
- {
- if(droga[i][j]=='x')
- {
- cout<<' ';
- }
- else
- {
- cout<<droga[i][j];
- }
- }
- cout<<endl;
- }
- re(sx-1, sy, kx, ky);
- }
- }
- main()
- {
- ifstream dane;
- dane.open("lab.txt");
- int bok;
- dane>>bok;
- char znaki[bok][bok];
- int y_st, x_st, y_end, x_end;
- string wczyt;
- getline(dane,wczyt);
- wczyt="";
- for(int i=0; i<bok; i++)
- {
- getline(dane,wczyt);
- for(int n=0; n<bok; n++)
- znaki[i][n]=wczyt[n];
- wczyt="";
- }
- for(int i=0; i<bok; i++)
- {
- cout<<endl;
- for(int n=0; n<bok; n++)
- {
- cout<<znaki[i][n];
- if(znaki[i][n]=='A')
- x_st=n, y_st=i;
- if(znaki[i][n]=='B')
- x_end=n, y_end=i;
- }
- }
- //cout<<endl<<x_st<<endl<<y_st<<endl<<x_end<<endl<<y_end<<endl;
- for(int i=0; i<bok; i++)
- {
- for(int j=0; j<bok; j++) droga[i][j]=znaki[i][j];
- }
- re(y_st, x_st, y_end, x_end);
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement