Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*in the name of Allah */
- # include <list>
- # include <deque>
- # include <bitset>
- # include <algorithm>
- # include <functional>
- # include <numeric>
- # include <utility>
- # include <sstream>
- # include <iostream>
- # include <iomanip>
- # include <cstdio>
- # include <cmath>
- # include <cstdlib>
- # include <ctime>
- # include <set>
- # include <map>
- # include <cmath>
- # include <queue>
- # include <limits>
- # include <stack>
- # include <vector>
- # include <cstring>
- # include <cstdio>
- using namespace std;
- # define MEM(array,w) memset(array,w,sizeof array)
- # define ULL unsigned long long
- # define eps 1e-9
- # define SS stringstream
- # define PR pair<int , int>
- # define all(c) (c).begin(), (c).end()
- # define FOR(i, a, b) for (int i=a; i<b; i++)
- # define REP(i, a) FOR(i, 0, a)
- # define rive(s) reverse(s.begin(),s.end())
- # define OK(R,C) if(i>=0 && j>=0 && j<=C && i<=R)
- # define MPSS map<string, string>
- # define MPIS map<int, string>
- # define MPSI map<string, int>
- # define MPII map<int, int>
- # define MPIC map<int,char>
- # define MPCI map<char, int>
- # define VS vector<string>
- # define VI vector<int>
- # define VC vector<char>
- # define VB vector<bool>
- # define pb push_back
- # define mp make_pair
- template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
- int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
- bool isprime(int n){if( n<2) return 0;for( int i=2; i*i<=n ; i++)if(n%i==0)return 0; return 1;return 0;}
- int pel(string s){string t;t=s;reverse(t.begin(),t.end());if(s==t)return 1;return 0;}
- int row,col;
- char maze[40][90];
- vector< pair<int, int> >vp;
- bool visited[40][90];
- int dr [] = {1,-1,0,0};
- int dc [] = {0,0,1,-1};
- void dfs(int i, int j, char ch)
- {
- if(i<0||j<0||i>vp[i].first|| j>vp[i].second||maze[i][j]=='X'||visited[i][j]==1)return;
- if(maze[i][j]==' ' || maze[i][j]==ch)
- maze[i][j]=ch;
- visited[i][j]=1;
- for ( int k = 0; k < 4; k++ )
- dfs (i + dr [k], j + dc [k],ch);
- }
- int main()
- {
- int test,Ctest=0;
- char s[90];
- row=col=0;
- MEM(visited,0);
- char fin[81];
- while(gets(s))
- {
- if(s[0]!='_'){
- strcpy(maze[row],s);
- col=strlen(s);
- row++;
- vp.push_back(mp(row,col));
- }else
- {
- strcpy(fin,s);
- for(int i=0;i<vp.size();i++)
- {
- for(int j=0;j<vp[i].second;j++){
- while(maze[i][j]==' ')j++;
- if(maze[i][j]!=' '&&maze[i][j]!='X')
- {
- char ch;ch=maze[i][j];
- dfs(i,j,ch);
- }
- }
- }
- for(int i=0;i<vp.size();i++){
- for(int j=0;j<vp[i].second;j++)
- cout<<maze[i][j];
- cout<<endl;}cout<<fin<<endl; vp.clear();row=0;MEM(visited,0);}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement