Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <sstream>
- #include <queue>
- using namespace std;
- queue<int> checkedI;
- queue<int> checkedJ;
- bool isChecked ( int i , int j )
- {
- int SIZ = checkedI.size() ;
- for ( int G = 0 ; G < SIZ ; ++G)
- {
- if ( ( i == checkedI.front() ) && ( j == checkedJ.front() ) )
- {
- return 1 ;
- }
- checkedI.push( checkedI.front());
- checkedI.pop() ;
- checkedJ.push( checkedJ.front()) ;
- checkedJ.pop() ;
- }
- return 0 ;
- }
- int main()
- {
- int R = 0 ;
- int C = 0 ;
- string sizes ;
- getline ( cin , sizes ) ;
- istringstream istr ( sizes ) ;
- istr >> R >> C ;
- vector < vector < char > > matrix ( R ) ;
- string line ;
- char tempChar = '_' ;
- for ( int i = 0 ; i < R ; ++i )
- {
- matrix[i].resize( C ) ;
- getline ( cin , line ) ;
- //cout << line ;
- istringstream istr ( line ) ;
- for ( int j = 0 ; j < C ; ++j )
- {
- istr >> tempChar ;
- matrix [i][j] = tempChar ;
- }
- }
- queue<int> toCheckI;
- queue<int> toCheckJ;
- string ch ;
- getline ( cin , ch ) ;
- char fillChar = ch[0];
- int startRow = 0 ;
- int startCol = 0 ;
- string pos;
- getline ( cin , pos ) ;
- istringstream istr1 ( pos ) ;
- istr1 >> startRow >> startCol ;
- char startChar = matrix[startRow][startCol] ;
- // MAIN SEARCH BODY++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- int i = startRow ;
- int j = startCol ;
- toCheckI.push (i) ;
- toCheckJ.push (j) ;
- while ( !( toCheckI.empty() ) )
- {
- i = toCheckI.front();
- j = toCheckJ.front();
- checkedI.push(i) ;
- checkedJ.push(j) ;
- matrix[i][j] = fillChar ;
- // -----------------------------PROVERKA GORNO POLE-------------------------------
- if ( ( ( i - 1 ) >= 0 ) && ( matrix [i-1][j] == startChar ) && ( !( isChecked ( (i-1) , j) ) ) )
- { //&& ( !( isChecked ( (i-1) , j , checkedI , checkedJ ) ) )
- toCheckI.push ( i - 1 ) ;
- toCheckJ.push ( j ) ;
- }
- // -----------------------------PROVERKA DOLNO POLE-------------------------------
- if ( ( ( i + 1 ) <= ( R - 1 ) ) && ( matrix [i+1][j] == startChar ) && ( !( isChecked ( (i+1) , j) ) ))
- { //&& ( !( isChecked ( (i+1) , j , checkedI , checkedJ ) ) )
- toCheckI.push ( i + 1 ) ;
- toCheckJ.push ( j ) ;
- }
- // -----------------------------PROVERKA LQVO POLE-------------------------------
- if ( ( ( j - 1 ) >= 0 ) && ( matrix [i][j-1] == startChar ) && ( !( isChecked ( i , ( j - 1 ) ) ) ) )
- { //&& ( !( isChecked ( i , ( j - 1 ) , checkedI , checkedJ ) )
- toCheckI.push ( i ) ;
- toCheckJ.push ( j - 1 ) ;
- }
- // -----------------------------PROVERKA DQSNO POLE-------------------------------
- if ( ( ( j + 1 ) <= ( C - 1 ) ) && ( matrix [i][j+1] == startChar ) && ( !( isChecked ( i , ( j + 1 ) ) ) ) )
- { //&& ( !( isChecked ( i , ( j + 1 ) , checkedI , checkedJ ) ) )
- toCheckI.push ( i ) ;
- toCheckJ.push ( j + 1 ) ;
- }
- toCheckI.pop();
- toCheckJ.pop();
- }
- string outt;
- for ( int i = 0 ; i < R ; ++i )
- {
- for ( int j = 0 ; j < C ; ++j )
- {
- outt.push_back( matrix[i][j] );
- }
- outt.push_back( '\n' ) ;
- }
- cout << outt ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement