Advertisement
Guest User

eminemvenom

a guest
Oct 18th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5. int L[8][8];
  6. int n,m,xs,ys,xb,yb;
  7. int dx[8]={-2,-1,1,2,2,1,-1,-2};
  8. int dy[8]={1,2,2,1,-1,-2,-2,-1};
  9. void citire()
  10. {
  11. cout<<"n=";cin>>n;
  12. cout<<"m=";cin>>m;
  13. for(int i=1;i<=n;i++)
  14. for(int j=1;j<=n;j++) f>>L[i][j];
  15. f.close();
  16. }
  17. void bordare()
  18. {
  19. for(int i=0;i<=n+1;i++)
  20. {
  21. L[i][0]=1;L[i][m+1]=1;
  22. }
  23. for(int i=0;i<=m+1;i++)
  24. {
  25. L[0][i]=1;L[n+1][i]=1;
  26. }
  27. for(int i=0;i<=n+1;i++)
  28. {
  29. L[i][0]=1;L[i][m+1]=1;
  30. }
  31. for(int i=0;i<=m+1;i++)
  32. {
  33. L[0][i]=1;L[n+1][i]=1;
  34. }
  35. }
  36. void afis()
  37. {
  38. g<<"sol nr"<<nrsol++<<endl;
  39. for(int i=1;i<=n;i++)
  40. {
  41. for(int j=1;j<=m;j++)
  42. if(L[i][j]==2)
  43. g<<'*';
  44. else g<<L[i][j];
  45. g<<endl;
  46. }
  47. }
  48. void cauta(int x,int y)
  49. {
  50. L[x][y]=2;
  51. if(x==xb&&y==yb)
  52. afis();
  53. else for (int dir=0;dir<8;dir++)
  54. if(!L[x+dx[dir]][y+dy[dir]])
  55. cauta(x+dx[dir],y+dy[dir]);
  56. L[x][y]=0;
  57. }
  58. int main()
  59. {citire();
  60. bordare();
  61. cauta(xs,ys);
  62. if(!nrsol)g<<"nu exista solutii"<<endl;
  63. g.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement