Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef vector< vector<char> > Matriu;
- void omplir(Matriu&f, int a, int b){
- if(a>0){
- if(f[a-1][b]=='A'){
- f[a-1][b]='F';
- omplir(f,a-1,b);
- }
- }
- if(a<f.size()-1){
- if(f[a+1][b]=='A'){
- f[a+1][b]='F';
- omplir(f,a+1,b);
- }
- }
- if(b>0){
- if(f[a][b-1]=='A'){
- f[a][b-1]='F';
- omplir(f,a,b-1);
- }
- }
- if(b<f[0].size()-1){
- if(f[a][b+1]=='A'){
- f[a][b+1]='F';
- omplir(f,a,b+1);
- }
- }
- }
- void foc(Matriu&f,int n,int m){
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j){
- if(f[i][j]=='F'){
- f[i][j]='F';
- omplir(f,i,j);
- }
- }
- }
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j){
- if(f[i][j]=='F') f[i][j]='.';
- }
- }
- }
- int main(){
- int n,m;
- while(cin>>n){
- cin>>m;
- Matriu f(n, vector<char>(m));
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j) cin>>f[i][j];
- }
- foc(f,n,m);
- for(int i=0;i<n;++i){
- for(int j=0;j<m;++j){
- cout<<f[i][j];
- }
- cout<<endl;
- }
- cout<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement