document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. #define MAX_ROWS 1000
  6. #define MAX_COLS 1000
  7.  
  8. int mapCheck[MAX_ROWS][MAX_COLS]={0};
  9. char map[MAX_ROWS][MAX_COLS]={0};
  10.  
  11. void DFS(int row, int col, char ch);
  12.  
  13. int main(){
  14.     int n;
  15.     cin>>n;
  16.     for(int world=1;world<=n;world++){
  17.         int rows,cols;
  18.         cin>>rows>>cols;
  19.         for(int r=1;r<=rows;r++){
  20.             for(int c=1;c<=cols;c++){
  21.                 char ch;
  22.                 cin>>ch;
  23.                 map[r][c]=ch;
  24.             }
  25.         }
  26.        
  27.        
  28.         int ASCII[256]={0};
  29.         for(int r=1;r<=rows;r++){
  30.             for(int c=1;c<=cols;c++){
  31.                 if(mapCheck[r][c]==0){
  32.                     DFS(r ,c , map[r][c]);
  33.                     ASCII[ map[r][c] ]++;
  34.                 }
  35.             }
  36.         }
  37.        
  38.         int maxStates=0;
  39.         for(int i=0;i<256;i++){
  40.             maxStates = (ASCII[i]>maxStates) ? ASCII[i] : maxStates;
  41.         }
  42.  
  43.         cout<<"World #"<<world<<endl;
  44.         for(int states=maxStates; states>=0 ; states--){
  45.             for(int ch=0;ch<256;ch++){
  46.                 if(ASCII[ch]==states && states>0){
  47.                     cout<<(char)ch<<": "<<states<<endl;
  48.                 }
  49.                
  50.             }
  51.         }
  52.        
  53.         for(int i=0;i<MAX_ROWS;i++){
  54.             for(int j=0;j<MAX_COLS;j++){
  55.                 map[i][j]=0;
  56.                 mapCheck[i][j]=0;
  57.             }
  58.         }
  59.                
  60.  
  61.     }
  62.  
  63.     return 0;
  64. }
  65.  
  66.  
  67.  
  68.  
  69.  
  70. void DFS(int row, int col, char ch){
  71.     mapCheck[row][col]=1;
  72.     if(mapCheck[row-1][col]==0  && map[row-1][col]==ch){
  73.         DFS(row-1,col,ch);
  74.     }
  75.     if(mapCheck[row][col+1]==0  && map[row][col+1]==ch){
  76.         DFS(row,col+1,ch);
  77.     }
  78.     if(mapCheck[row+1][col]==0  && map[row+1][col]==ch){
  79.         DFS(row+1,col,ch);
  80.     }
  81.     if(mapCheck[row][col-1]==0  && map[row][col-1]==ch){
  82.         DFS(row,col-1,ch);
  83.     }
  84. }
');