Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int TABL[52][52];
  6.  
  7. int PATH[52][52];
  8.  
  9. void Wave(int a,int b, int n){
  10. TABL[a][b]=n;
  11. if (a-1>-1){
  12. if (TABL[a-1][b]>n+1)
  13. Wave(a-1, b, n+1);
  14. }
  15. if (a+1<53){
  16. if (TABL[a+1][b]>n+1)
  17. Wave(a+1, b, n+1);
  18. }
  19. if (b-1>-1){
  20. if (TABL[a][b-1]>n+1)
  21. Wave(a, b-1, n+1);
  22. }
  23. if (b+1<53){
  24. if (TABL[a][b+1]>n+1)
  25. Wave(a, b+1, n+1);
  26. }
  27. return;
  28. }
  29.  
  30.  
  31.  
  32. void WaveBack(int a, int b, int n){
  33. if(TABL[a][b]==-1)
  34. return;
  35.  
  36. PATH[a][b]=1;
  37.  
  38. if (a-1>0){
  39. if (TABL[a-1][b]==n-1){
  40. WaveBack(a-1, b, n-1);
  41. //cout<<a<<b<<endl;
  42. return;
  43. }
  44. }
  45. if (a+1<52){
  46. if (TABL[a+1][b]==n-1){
  47. WaveBack(a+1, b, n-1);
  48. //cout<<a<<b<<endl;
  49. return;
  50. }
  51. }
  52. if (b-1>0){
  53. if (TABL[a][b-1]==n-1){
  54. WaveBack(a, b-1, n-1);
  55. //cout<<a<<b<<endl;
  56. return;
  57. }
  58. }
  59. if (b+1<52){
  60. if (TABL[a][b+1]==n-1){
  61. WaveBack(a, b+1, n-1);
  62. //cout<<a<<b<<endl;
  63. return;
  64. }
  65. }
  66. }
  67.  
  68. int main()
  69. {
  70. cout<<"Enter firstly length, then width of your field"<<endl;
  71. int N, M;
  72. cin>>N>> M;
  73.  
  74.  
  75. //--------------------------------------------------------Writing the table---------------------------------------------
  76.  
  77. int stx, sty, endx, endy;
  78.  
  79. cout << "If there is a start point here, press 0" << endl ;
  80. cout << "IF there is a easy go point, press 1" << endl ;
  81. cout << "If there is an obstacle, press 2" << endl ;
  82. cout << "If there is end point, press 3" << endl ;
  83.  
  84. for ( int i = 1 ; i < N + 1 ; i ++ )
  85. {
  86. for ( int j = 1 ; j < M + 1 ; j ++ ) {
  87. //------------------------------drawing a table-------------------------------------
  88.  
  89. for (int i_=1; i_<N+1; i_++) {
  90. for (int j_=1; j_<M+1; j_++){
  91. if (i==i_ && j==j_)
  92. std::cout << "?";
  93. else if(TABL[i_][j_]==-1)
  94. cout<<"*";
  95. else if(endx==i_ && endy==j_)
  96. cout<<"x";
  97. else if(i_==stx && j_==sty)
  98. cout<<"+";
  99. else
  100. cout<<"-";
  101. }
  102. std::cout << std::endl;
  103. }
  104. cout<<"/////////////////////////////////////"<<endl;
  105.  
  106.  
  107.  
  108. //-----------------------------------going on---------------------------------------
  109. int cell_;
  110. cin>>cell_;
  111. if (cell_==0){
  112. TABL[i][j]=0;
  113. stx=i;
  114. sty=j;
  115. }
  116. else if (cell_==1)
  117. TABL[i][j]=N*M;
  118. else if (cell_==2)
  119. TABL[i][j]=-1;
  120. else if (cell_==3){
  121. TABL[i][j]=N*M;
  122. endx=i;
  123. endy=j;
  124. }
  125.  
  126. }
  127. for (int i=0; i<N+2; i++){
  128. TABL[0][i]=-1;
  129. TABL[N+1][i]=-1;
  130. TABL[i][0]=-1;
  131. TABL[i][M+1]=-1;
  132. }
  133. }
  134.  
  135.  
  136. //---------------------------------------------------------something-------------------------
  137.  
  138.  
  139.  
  140.  
  141. //--------------------------------------------------------------WaveAlg-------------------------------------------
  142.  
  143.  
  144. Wave(stx, sty, 0);
  145.  
  146. if (TABL[endx][endy]==M*N){
  147. cout<<"Sorry, there is no way... :-(";
  148. cin>>M;
  149. return 0;
  150. }
  151. else
  152. WaveBack(endx, endy, TABL[endx][endy]);
  153.  
  154.  
  155. //------------------------------------------------------------Drawing your path-----------------------------------------------
  156.  
  157.  
  158. for (int i=1; i<N+1; i++) {
  159. for (int j=1; j<M+1; j++){
  160. if (PATH[i][j]==1)
  161. std::cout << "+";
  162. else if(TABL[i][j]==-1)
  163. cout<<"*";
  164. else
  165. cout<<"-";
  166. }
  167. std::cout << std::endl;
  168. }
  169.  
  170.  
  171. return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement