题目
有些人用深搜写的,当然我这弱弱的,只理解纯模拟。。。
纯模拟,第一次写了那么长的代码,我自己也是够坚韧不拔的,,,,必须留念啊!!!
注意,G包含C,E包含L,R包含P,(照图说O应该不包含C,但是不排除掉这种情况,就wa掉了,所以要排除O包含C的情况。。)
#include<stdio.h> #include<string.h> int n,m; char s2[330][330]; int vis[30]; void fun(){ //a if(vis[0]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int no=0,jj; for(jj=j+5;jj<j+8;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+9;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+5;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+10;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+11;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[0]=1;break;} } if(vis[0]==1)break; } } /* MMMMMMMMMMM1 MM11111111MM MM11111111MM MMMMMMMMMMM1 MM11111111MM MM11111111MM MMMMMMMMMMM1 */ //b if(vis[1]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int jj,no=0; for(jj=j;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[1]=1;break;} } if(vis[1]==1)break; } } /* 111MMMMMMMM11 1MM1111111MM1 MM111111111MM MM11111111111 MM111111111MM 1MM1111111MM1 111MMMMMMMM11 */ //c if(vis[2]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int jj,no=0; for(jj=j+3;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; if(s2[i+3][11]=='M'||s2[i+4][10]=='M'){no=1;continue;} for(jj=j+1;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+11;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[2]=1;break;} } if(vis[2]==1)break; } } /* MMMMMMMMMMM111 MM111111111MM1 MM1111111111MM MM1111111111MM MM1111111111MM MM111111111MM1 MMMMMMMMMMM111 */ //d if(vis[3]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int jj,no=0; for(jj=j;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[3]=1;break;} } if(vis[3]==1)break; } } /* MMMMMMMMMMMM MM1111111111 MM1111111111 MMMMMMMMMMMM MM1111111111 MM1111111111 MMMMMMMMMMMM */ //e if(vis[4]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int no=0,jj; for(jj=j;jj<j+12;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+12;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[4]=1;break;} } if(vis[4]==1)break; } } /* MMMMMMMMMMMMM MM11111111111 MM11111111111 MMMMMMMMMMMMM MM11111111111 MM11111111111 MM11111111111 */ //f if(vis[5]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int no=0,jj; for(jj=j;jj<j+13;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+13;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[5]=1;break;} } if(vis[5]==1)break; } } /* 111MMMMMMMM11 1MM1111111MM1 MM111111111MM MM11111111111 MM111111MMMMM 1MM1111111MM1 111MMMMMMMMM1 */ //g if(vis[6]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int no=0,jj; for(jj=j+3;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+13;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[6]=1;break;} } if(vis[6]==1)break; } } /* MM111111111MM MM111111111MM MM111111111MM MMMMMMMMMMMMM MM111111111MM MM111111111MM MM111111111MM */ //h if(vis[7]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(x=0;x<3;x++){ for(jj=j;jj<j+2;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; for(jj=j+11;jj<j+13;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; for(jj=j;jj<j+13;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(x=4;x<7;x++){ for(jj=j;jj<j+2;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; for(jj=j+11;jj<j+13;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; if(no==0){vis[7]=1;break;} } if(vis[7]==1)break; } } /* MMMMMM 11MM11 11MM11 11MM11 11MM11 11MM11 MMMMMM */ //i if(vis[8]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+6;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(x=1;x<6;x++){ for(jj=j+2;jj<j+4;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; for(jj=j;jj<j+6;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[8]=1;break;} } if(vis[8]==1)break; } } /* 1MMMMMMMM 1111MM111 1111MM111 1111MM111 MM11MM111 MMM1MM111 11MMMM111 */ //j if(vis[9]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j+1;jj<j+9;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(x=1;x<4;x++){ for(jj=j+4;jj<j+6;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+6;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[9]=1;break;} } if(vis[9]==1)break; } } /* MM111111MMM1 MM11111MMM11 MM111MMM1111 MMMMM1111111 MM111MMM1111 MM11111MMM11 MM111111MMMM */ //k if(vis[10]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+2;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+10;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+8;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+5;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+8;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+10;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[10]=1;break;} } if(vis[10]==1)break; } } /* MM1111111111 MM1111111111 MM1111111111 MM1111111111 MM1111111111 MM1111111111 MMMMMMMMMMMM */ //l if(vis[11]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; if(s2[i+3][j+2]=='M'){no=1;continue;} for(x=0;x<6;x++){ for(jj=j;jj<j+2;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; for(jj=j;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[11]=1;break;} } if(vis[11]==1)break; } } /* MM1111111111MM MMMM111111MMMM MM1MM1111MM1MM MM11MMMMM111MM MM1111M11111MM MM1111111111MM MM1111111111MM */ //m if(vis[12]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+2;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+14;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; if(s2[i+2][j]!='M'||s2[i+2][j+1]!='M'||s2[i+2][j+3]!='M'|| s2[i+2][j+4]!='M'||s2[i+2][j+9]!='M'||s2[i+2][j+10]!='M'|| s2[i+2][j+12]!='M'||s2[i+2][j+13]!='M'){no=1;continue;} for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+9;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; if(s2[i+4][j]!='M'||s2[i+4][j+1]!='M'||s2[i+4][j+6]!='M'|| s2[i+4][j+12]!='M'||s2[i+4][j+13]!='M'){no=1;continue;} for(x=5;x<7;x++){ for(jj=j;jj<j+2;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; for(jj=j+12;jj<j+14;jj++)if(s2[i+x][jj]!='M'){no=1;break;}if(no==1)break; }if(no==1)continue; if(no==0){vis[12]=1;break;} } if(vis[12]==1)break; } } /* MMM111111111MM MMMM11111111MM MM1MM1111111MM MM11MM111111MM MM1111MM1111MM MM111111MMM1MM MM11111111MMMM */ //n if(vis[13]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+3;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+5;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+8;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+14;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[13]=1;break;} } if(vis[13]==1)break; } } /* 1111MMMMMM1111", 11MMM1111MMM11", 1MMM111111MMM1", MM1111111111MM", 1MMM111111MMM1", 11MMM1111MMM11", 1111MMMMMM1111", */ //o if(vis[14]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j+4;jj<j+10;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+10;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[14]=1;break;} } if(vis[14]==1)break; } } /* MMMMMMMMMMM111", MM111111111MM1", MM1111111111MM", MM111111111MM1", MMMMMMMMMMM111", MM111111111111", MM111111111111", */ //p if(vis[15]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; if(s2[i+5][j+11]=='M'){no=1;continue;} for(jj=j;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[15]=1;break;} } if(vis[15]==1)break; } } /* 1111MMMMMM1111", 11MMM1111MMM11", 1MMM111111MMM1", MM1111111111MM", 1MMM1MMMM1MMM1", 11MMM11MMMMM11", 11111MMMM1MMMM", */ //q if(vis[16]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j+4;jj<j+10;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+9;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+9;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+14;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[16]=1;break;} } if(vis[16]==1)break; } } /* MMMMMMMMMMM111", MM111111111MM1", MM1111111111MM", MM111111111MM1", MMMMMMMMMMM111", MM11111111MM11", MM111111111MMM", */ //r if(vis[17]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+12;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+14;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[17]=1;break;} } if(vis[17]==1)break; } } /* 111MMMMMMMM111", 11MM1111111MM1", 1MMM1111111MMM", 111MMMMM111111", MMM111MMMM1111", 11MMM11111MMM1", 1111MMMMMMM111", */ //s if(vis[18]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j+3;jj<j+11;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+8;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+10;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+11;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[18]=1;break;} } if(vis[18]==1)break; } } /* MMMMMMMMMMMM", MMMMMMMMMMMM", 11111MM11111", 11111MM11111", 11111MM11111", 11111MM11111", 11111MM11111", */ //t if(vis[19]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+12;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+12;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[19]=1;break;} } if(vis[19]==1)break; } } /* MM1111111111MM", MM1111111111MM", MM1111111111MM", MM1111111111MM", MMM11111111MMM", MMM11111111MMM", 11MMMMMMMMMM11", */ //u if(vis[20]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+2;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+14;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+14;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[20]=1;break;} } if(vis[20]==1)break; } } /* MMMM111111MMMM", 1MMM111111MMM1", 1MMM111111MMM1", 11MMM1111MMM11", 111MMM11MMM111", 1111MM11MM1111", 11111MMMM11111", */ //v if(vis[21]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+4;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+14;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+10;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+6;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+10;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+9;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[21]=1;break;} } if(vis[21]==1)break; } } /* MM1111111111MM", MM1111111111MM", 1MM111MM111MM1", 1MM111MM111MM1", 1MM111MM111MM1", 1MM1MM11MM1MM1", 11MMM1111MMM11", */ //w if(vis[22]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+2;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+2;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+12;jj<j+14;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+8;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+8;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+8;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+3;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+6;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+10;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+11;jj<j+13;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[22]=1;break;} } if(vis[22]==1)break; } } /* MMM111111MMM", 1MMM1111MMM1", 11MMM11MMM11", 1111MMMM1111", 11MMM11MMM11", 1MMM1111MMM1", MMM111111MMM", */ //x if(vis[23]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+3;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+3;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+10;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+10;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+8;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[23]=1;break;} } if(vis[23]==1)break; } } /* MMM111111MMM", 1MMM1111MMM1", 11MMM11MMM11", 1111MMMM1111", 11111MM11111", 11111MM11111", 11111MM11111", */ //y if(vis[24]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+3;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+9;jj<j+12;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+1;jj<j+4;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+8;jj<j+11;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+5;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+10;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+4;jj<j+8;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[24]=1;break;} } if(vis[24]==1)break; } } /* MMMMMMMMMM1", 1111111MM11", 111111MM111", 11111MM1111", 111MM111111", 11MM1111111", MMMMMMMMMMM" */ //z if(vis[25]==0){ for(int i=0;i<n-6;i++){ for(int j=0;j<m;j++){ int x,no=0,jj; for(jj=j;jj<j+10;jj++)if(s2[i][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+7;jj<j+9;jj++)if(s2[i+1][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+6;jj<j+8;jj++)if(s2[i+2][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+5;jj<j+7;jj++)if(s2[i+3][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+3;jj<j+5;jj++)if(s2[i+4][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j+2;jj<j+4;jj++)if(s2[i+5][jj]!='M'){no=1;break;}if(no==1)continue; for(jj=j;jj<j+11;jj++)if(s2[i+6][jj]!='M'){no=1;break;}if(no==1)continue; if(no==0){vis[25]=1;break;} } if(vis[25]==1)break; } } } int main() { char s[330][330]; while(scanf("%d%d",&n,&m)!=EOF) { memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) scanf("%s",s[i]); memset(s2,0,sizeof(s2)); for(int i=0;i<n;i++)for(int j=0;j<m;j++)s2[i][j]=s[i][j]; fun(); memset(s2,0,sizeof(s2)); for(int i=n-1;i>=0;i--)for(int j=m-1;j>=0;j--)s2[n-i-1][m-j-1]=s[i][j]; fun(); for(int i=0;i<26;i++) if(vis[i]==1)printf("%c",'A'+i); puts(""); } return 0; }