Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. char niz[210][210];
  7. int xpoc, ypoc, xmeta,ymeta;
  8. int n, m , d,rjesx, rjesy;
  9. int resx, resy;
  10. bool provjera(int k)
  11. {
  12. if(k == 0)
  13. {
  14. xpoc--;
  15. while(xpoc >= 0)
  16. {
  17. xpoc--;
  18. if(niz[xpoc][ypoc] == '/' ) provjera(1);
  19.  
  20. if(niz[xpoc][ypoc] == '\\') provjera(3);
  21.  
  22. if(niz[xpoc][ypoc] == 'E') return 1;
  23. }
  24. }
  25. if(k== 1)
  26. {
  27. while(ypoc <= m)
  28. {
  29. ypoc ++;
  30. if(niz[xpoc][ypoc] == '/') provjera(0);
  31. if(niz[xpoc][ypoc] == '\\') provjera(2);
  32. if(niz[xpoc][ypoc] == 'E') return 1;
  33. }
  34. }
  35. if(k == 2)
  36. {
  37.  
  38. while(xpoc <= n)
  39. {
  40. xpoc ++;
  41. if(niz[xpoc][ypoc] == '/') provjera(3);
  42. if(niz[xpoc][ypoc] == '\\') provjera(1);
  43. if(niz[xpoc][ypoc] == 'E') return 1;
  44. }
  45. }
  46. if(k == 3)
  47. {
  48.  
  49. while(ypoc >= 0)
  50. {
  51. ypoc--;
  52. if(niz[xpoc][ypoc] == '/') provjera(2);
  53. if(niz[xpoc][ypoc] == '\\') provjera(0);
  54. if(niz[xpoc][ypoc] == 'E') return 1;
  55. }
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61. bool promjena()
  62. {
  63.  
  64. for(int i = 0; i < n; i++)
  65. {
  66. for(int j = 0; j < m ; j++)
  67. {
  68. if(niz[i][j] == '/')
  69. {
  70. niz[i][j] = '\\';
  71. xpoc = resx;
  72. ypoc = resy;
  73. if(provjera(d) == 1)
  74. {
  75. rjesx = i+1;
  76. rjesy = j+1;
  77. return 1;
  78. }
  79. niz[i][j] = '/';
  80. }
  81. if (niz[i][j] == '\\' )
  82. {
  83. niz[i][j] = '/';
  84. xpoc = resx;
  85. ypoc = resy;
  86. if(provjera(d) == 1)
  87. {
  88. rjesx = i+1;
  89. rjesy = j+1;
  90. return 1;
  91. }
  92. niz[i][j] = '\\';
  93. }
  94. }
  95. }
  96. return 0;
  97.  
  98.  
  99. }
  100.  
  101. int main()
  102. {
  103.  
  104.  
  105. cin >> n >> m;
  106. cin >> d;
  107. for(int i = 0; i < n; i++)
  108. {
  109. for(int j = 0; j < m; j++)
  110. {
  111. cin >> niz[i][j];
  112.  
  113. if(niz [ i ][ j ] == 'E' )
  114. {
  115. xmeta = i;
  116. ymeta = j;
  117. }
  118. if (niz[i][j] == 'S')
  119. {
  120. xpoc = i;
  121. ypoc = j;
  122. }
  123. }
  124. }
  125. resx = xpoc;
  126. resy = ypoc;
  127.  
  128. if(provjera(d) == 1) cout << "nije potrebno vrsiti izmjene" << endl;
  129. else
  130. {
  131.  
  132. if(promjena() == 1) cout << rjesx << " " << rjesy << endl;
  133. else cout << "nemoguce" << endl;
  134. }
  135.  
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement