Violent solution.
1#include <cstdio>2#include <cstring>3 4 #defineMAXN 1055 6 CharMAP[MAXN][MAXN];7 Charvisit[ -];8 intN, M;9 Ten BOOLCheckCharc) { One intI, J; A intX1=MAXN, Y1=MAXN, x2=-1, y2=-1; - - for(i=0; i<n; ++i) { the for(j=0; j<m; ++j) { - if(Map[i][j] = =c) { - if(i<x1) x1 =i; - if(j<y1) y1 =J; + if(i>x2) x2 =i; - if(j>y2) y2 =J; + } A } at } - if(x2-x1<2|| y2-y1<2) - return false; - for(i=x1; i<=x2; + +)i) - if(Map[i][y1]!=c | | map[i][y2]!=c) - return false; in for(j=y1; j<=y2; + +)j) - if(Map[x1][j]!=c | | map[x2][j]!=c) to return false; + for(i=x1+1; i<x2; ++i) - for(j=y1+1; j<y2; ++j) the if(Map[i][j]! ='.') * return false; $ return true;Panax Notoginseng } - the intMain () { + inti; A intJ; the + while(SCANF ("%d%d", &n, &m)!=eof && (n| |m)) { -memset (Visit,false,sizeof(visit)); $ for(i=0; i<n; ++i) { $scanf"%s", Map[i]); - for(j=0; j<m; ++j) { - if(Map[i][j]! ='.') { thevisit[map[i][j]-'A'] =true; - }Wuyi } the } - for(i=0; i< -; ++i) { Wu if(Visit[i] && check (i+'A')) -printf"%c", i+'A'); About } $printf"\ n"); - } - - return 0; A}