Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <queue>
  6.  
  7. using namespace std;
  8. queue<int> checkedI;
  9. queue<int> checkedJ;
  10.  
  11.  
  12.  
  13. bool isChecked ( int i , int j )
  14. {
  15. int SIZ = checkedI.size() ;
  16. for ( int G = 0 ; G < SIZ ; ++G)
  17. {
  18. if ( ( i == checkedI.front() ) && ( j == checkedJ.front() ) )
  19. {
  20. return 1 ;
  21. }
  22. checkedI.push( checkedI.front());
  23. checkedI.pop() ;
  24. checkedJ.push( checkedJ.front()) ;
  25. checkedJ.pop() ;
  26. }
  27. return 0 ;
  28. }
  29.  
  30. int main()
  31. {
  32. int R = 0 ;
  33. int C = 0 ;
  34. string sizes ;
  35. getline ( cin , sizes ) ;
  36. istringstream istr ( sizes ) ;
  37. istr >> R >> C ;
  38. vector < vector < char > > matrix ( R ) ;
  39. string line ;
  40. char tempChar = '_' ;
  41. for ( int i = 0 ; i < R ; ++i )
  42. {
  43. matrix[i].resize( C ) ;
  44.  
  45. getline ( cin , line ) ;
  46. //cout << line ;
  47. istringstream istr ( line ) ;
  48. for ( int j = 0 ; j < C ; ++j )
  49. {
  50. istr >> tempChar ;
  51. matrix [i][j] = tempChar ;
  52. }
  53. }
  54. queue<int> toCheckI;
  55. queue<int> toCheckJ;
  56.  
  57. string ch ;
  58. getline ( cin , ch ) ;
  59. char fillChar = ch[0];
  60. int startRow = 0 ;
  61. int startCol = 0 ;
  62. string pos;
  63. getline ( cin , pos ) ;
  64. istringstream istr1 ( pos ) ;
  65. istr1 >> startRow >> startCol ;
  66.  
  67.  
  68. char startChar = matrix[startRow][startCol] ;
  69. // MAIN SEARCH BODY++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  70.  
  71. int i = startRow ;
  72. int j = startCol ;
  73.  
  74.  
  75. toCheckI.push (i) ;
  76. toCheckJ.push (j) ;
  77. while ( !( toCheckI.empty() ) )
  78. {
  79. i = toCheckI.front();
  80. j = toCheckJ.front();
  81.  
  82. checkedI.push(i) ;
  83. checkedJ.push(j) ;
  84. matrix[i][j] = fillChar ;
  85.  
  86. // -----------------------------PROVERKA GORNO POLE-------------------------------
  87. if ( ( ( i - 1 ) >= 0 ) && ( matrix [i-1][j] == startChar ) && ( !( isChecked ( (i-1) , j) ) ) )
  88. { //&& ( !( isChecked ( (i-1) , j , checkedI , checkedJ ) ) )
  89. toCheckI.push ( i - 1 ) ;
  90. toCheckJ.push ( j ) ;
  91. }
  92.  
  93. // -----------------------------PROVERKA DOLNO POLE-------------------------------
  94. if ( ( ( i + 1 ) <= ( R - 1 ) ) && ( matrix [i+1][j] == startChar ) && ( !( isChecked ( (i+1) , j) ) ))
  95. { //&& ( !( isChecked ( (i+1) , j , checkedI , checkedJ ) ) )
  96. toCheckI.push ( i + 1 ) ;
  97. toCheckJ.push ( j ) ;
  98. }
  99.  
  100. // -----------------------------PROVERKA LQVO POLE-------------------------------
  101. if ( ( ( j - 1 ) >= 0 ) && ( matrix [i][j-1] == startChar ) && ( !( isChecked ( i , ( j - 1 ) ) ) ) )
  102. { //&& ( !( isChecked ( i , ( j - 1 ) , checkedI , checkedJ ) )
  103. toCheckI.push ( i ) ;
  104. toCheckJ.push ( j - 1 ) ;
  105. }
  106.  
  107. // -----------------------------PROVERKA DQSNO POLE-------------------------------
  108. if ( ( ( j + 1 ) <= ( C - 1 ) ) && ( matrix [i][j+1] == startChar ) && ( !( isChecked ( i , ( j + 1 ) ) ) ) )
  109. { //&& ( !( isChecked ( i , ( j + 1 ) , checkedI , checkedJ ) ) )
  110. toCheckI.push ( i ) ;
  111. toCheckJ.push ( j + 1 ) ;
  112. }
  113.  
  114. toCheckI.pop();
  115. toCheckJ.pop();
  116.  
  117. }
  118.  
  119. string outt;
  120. for ( int i = 0 ; i < R ; ++i )
  121. {
  122. for ( int j = 0 ; j < C ; ++j )
  123. {
  124. outt.push_back( matrix[i][j] );
  125. }
  126. outt.push_back( '\n' ) ;
  127. }
  128. cout << outt ;
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement