/* ACM North Central Region, 1994-95 Problem G, Interpreting Control Sequences Ed Karrels, May 1996 */ #include void Put(char sc[10][10], int *x, int *y, int ovr, char c) { int i; if (!ovr) { for (i=8; i >= *x; i--) sc[i + 1][*y] = sc[i][*y]; } sc[*x][*y] = c; if (*x < 9) ++*x; } int main() { char sc[10][10]; int x, y, l, nl, ovr=1, i, j, cs=1; char c; while (scanf("%d ", &nl), nl) { for (i=0; i<10; i++) for (j=0; j<10; j++) sc[i][j] = ' '; x = y = 0; while (nl) { c = getchar(); if (c == '^') { c = getchar(); switch (c) { case 'b': x = 0; break; case 'c': for (i=0; i<10; i++) for (j=0; j<10; j++) sc[i][j] = ' '; break; case 'd': if (y<9) y++; break; case 'e': for (i=x; i<10; i++) sc[i][y] = ' '; break; case 'h': x = y = 0; break; case 'i': ovr = 0; break; case 'l': if (x>0) x--; break; case 'o': ovr = 1; break; case 'r': if (x<9) x++; break; case 'u': if (y>0) y--; break; case '^': Put(sc, &x, &y, ovr, '^'); break; } if (isdigit(c)) { y = c - '0'; x = getchar() - '0'; } } else if (c != '\n') { Put(sc, &x, &y, ovr, c); } else { nl--; } } /* while */ printf("Case %d\n", cs++); printf("+----------+\n"); for (i=0; i<10; i++) { putchar('|'); for (j=0; j<10; j++) { putchar(sc[j][i]); } putchar('|'); putchar('\n'); } printf("+----------+\n"); } return 0; }