/* Thu Mar 25 22:25:31 JST 2004 */ /* Thu Mar 25 23:24:46 JST 2004 */ #include int w, h; char s[32][64]; char superemum[32][32], infimum[32][32]; void simple_or() { int i, j; for (i = 0; i < h+1; i++) { for (j = 0; j < 2*w+1; j++) { if (s[i][j+2*w+2] != ' ') { infimum[i][j] = s[i][j+2*w+2]; } else if (s[i][j] != ' ') { infimum[i][j] = s[i][j]; } else { infimum[i][j] = ' '; } } } } void simple_and() { int i, j; for (i = 0; i < h+1; i++) { for (j = 0; j < 2*w+1; j++) { if (s[i][j+2*w+2] == s[i][j]) { superemum[i][j] = s[i][j]; } else { superemum[i][j] = ' '; } } } } void replace(char x, char y) { int i, j; for (i = 0; i < h+1; i++) { for (j = 0; j < 2*w+1; j++) { if (superemum[i][j] == x) { superemum[i][j] = y; } } } } int down(int y, int x) { int i = y, j = x, del = 0; if (superemum[i-1][j-1] != '_' || superemum[i-1][j+1] != '_') { del = 1; } for (i = y; ; i++) { if (superemum[i][j] != '|') { replace('@', ' '); return 1; } superemum[i][j] = '@'; if (superemum[i][j-1] == '_' && superemum[i][j+1] == '_') { if (del) { replace('@', ' '); return 1; } else { replace('@', '!'); return 0; } } } } int right(int y, int x) { int i = y, j = x, del = 0; if (superemum[i][j-1] != '|' || superemum[i+1][j-1] != '|') { del = 1; } for (j = x; ; j += 2) { if (superemum[i][j] != '_') { replace('@', ' '); return 1; } superemum[i][j] = '@'; if (superemum[i][j+1] == '|' && superemum[i+1][j+1] == '|') { if (del) { replace('@', ' '); return 1; } else { replace('@', '-'); return 0; } } } } int cut() { int i, j, result = 0; for (i = 1; i < h+1; i++) { for (j = 1; j < 2*w; j++) { if (superemum[i][j] == '|') { result |= down(i, j); } if (i < h) { if (superemum[i][j] == '_') { result != right(i, j); } } } } replace('!', '|'); replace('-', '_'); return result; } int main() { char tmp[1024]; int icase, i, j; for (icase = 1; ; icase++) { gets(tmp); sscanf(tmp, "%d %d", &w, &h); if (w == 0 && h == 0) { break; } for (i = 0; i < h+1; i++) { gets(s[i]); infimum[i][2*w+1] = superemum[i][2*w+1] = '\0'; } simple_or(); simple_and(); while (cut()) { ; } printf("Case %d:\n", icase); for (i = 0; i < h+1; i++) { printf("%s %s\n", infimum[i], superemum[i]); } printf("\n"); } return 0; }