#include #include #include using namespace std; int whoWins( vector map, int whoseOn , int x, int y,int height) { int width; width = map[0].length(); bool target = false; map[x][y] = 'X'; for ( int i = -1; i < 2; i++ ) for ( int j = -1; j < 2; j++ ) { if ( ( i == j ) || ( i == -j ) ) continue; if ( ( x+i < 0 ) || ( y + j < 0 ) || ( x + i >= height ) || ( y + j >= width ) ) continue; if ( map[x+i][y+j] == 'X' ) continue; int decision = whoWins( map, 1-whoseOn, x+i, y+j , height); if ( decision == whoseOn ) { target = true; break; } } if ( target ) return whoseOn; return 1-whoseOn; } int main() { int width, heigth; cin >> heigth >> width; while ( ( width != 0 ) || ( heigth != 0 ) ) { vector situation; for ( int i = 0; i < heigth; i++ ) { string s; cin >> s; situation.push_back(s); } for ( int i = 0; i < heigth; i++ ) { for ( int j = 0; j < width; j++ ) { if ( situation[i][j] == 'X' ) { cout << 'X'; continue; } int decision = whoWins( situation, 0,i,j,heigth); if ( decision == 0 ) cout << "A"; else cout << "B"; } cout << endl; } cout << endl; cin >> heigth >> width; } return 0; }