Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std ;
- int n , m , yo[2005][2005] ;
- string s[2005] ;
- int lx , ly , hx, hy ;
- void go( int x , int y )
- {
- if( x < 0 || x >= n ) return ;
- if( y < 0 || y >= m ) return ;
- if( s[x][y] == '*' )return ;
- if( yo[x][y] ) return ;
- yo[x][y] = 1 ;
- if( x < lx ) lx = x ;
- else if( x > hx ) hx = x ;
- if( y < ly ) ly = y ;
- else if( y > hy ) hy = y ;
- go( x +1 , y ) ;
- go( x , y+1 ) ;
- go( x , y-1 ) ;
- go( x -1 , y ) ;
- }
- int main()
- {
- cin >> n >> m ;
- for( int i = 0 ; i < n ; i++ )
- {
- cin >> s[i] ;
- }
- for( int i = 0 ; i < n ; i++ )
- {
- for( int j = 0 ; j < m ; j++ )
- {
- if( !yo[i][j] && s[i][j] == '.' )
- {
- lx = i ;
- ly = j ;
- hx = i ;
- hy = j ;
- go( i , j ) ;
- for( int r = lx ; r <= hx ; r++ )
- {
- for( int c = ly ; c <= hy ; c++ )
- {
- s[r][c] = '.' ;
- yo[r][c] = 1 ;
- }
- }
- }
- }
- }
- for( int i = 0 ; i < n ; i++ )
- {
- cout << s[i] <<endl;
- }
- return 0 ;
- }
- /*
- ***..*......*...****.*****.*.....**.*******.******.*..***.***.**
- ***..*......*...****.*****.*.....**.*******.******.*..***.***.**
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement