Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- #define MAX_ROWS 1000
- #define MAX_COLS 1000
- int mapCheck[MAX_ROWS][MAX_COLS]={0};
- char map[MAX_ROWS][MAX_COLS]={0};
- void DFS(int row, int col, char ch);
- int main(){
- int n;
- cin>>n;
- for(int world=1;world<=n;world++){
- int rows,cols;
- cin>>rows>>cols;
- for(int r=1;r<=rows;r++){
- for(int c=1;c<=cols;c++){
- char ch;
- cin>>ch;
- map[r][c]=ch;
- }
- }
- int ASCII[256]={0};
- for(int r=1;r<=rows;r++){
- for(int c=1;c<=cols;c++){
- if(mapCheck[r][c]==0){
- DFS(r ,c , map[r][c]);
- ASCII[ map[r][c] ]++;
- }
- }
- }
- int maxStates=0;
- for(int i=0;i<256;i++){
- maxStates = (ASCII[i]>maxStates) ? ASCII[i] : maxStates;
- }
- cout<<"World #"<<world<<endl;
- for(int states=maxStates; states>=0 ; states--){
- for(int ch=0;ch<256;ch++){
- if(ASCII[ch]==states && states>0){
- cout<<(char)ch<<": "<<states<<endl;
- }
- }
- }
- for(int i=0;i<MAX_ROWS;i++){
- for(int j=0;j<MAX_COLS;j++){
- map[i][j]=0;
- mapCheck[i][j]=0;
- }
- }
- }
- return 0;
- }
- void DFS(int row, int col, char ch){
- mapCheck[row][col]=1;
- if(mapCheck[row-1][col]==0 && map[row-1][col]==ch){
- DFS(row-1,col,ch);
- }
- if(mapCheck[row][col+1]==0 && map[row][col+1]==ch){
- DFS(row,col+1,ch);
- }
- if(mapCheck[row+1][col]==0 && map[row+1][col]==ch){
- DFS(row+1,col,ch);
- }
- if(mapCheck[row][col-1]==0 && map[row][col-1]==ch){
- DFS(row,col-1,ch);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement