황현 ¶
내 컴에선 잘 되는데 submit하면 런타임 에러가 뿜뿜! 왜일까~요?
#include <stdio.h> #define NULL_B 0x00 #define BACKSPACE 0x08 #define NEWLINE 0x0A #define ECHO(c) \ do { \ if(c == NEWLINE) { \ buffer[bi] = NULL_B; \ bi = 0; \ printf("%s\n", buffer); \ } else if(c == BACKSPACE) { \ --bi; \ } else \ buffer[bi++] = c; \ } while(0); #define ECHO_C ECHO(c) int main() { int T, i; char buffer[(10 * 1024) + 1] = { 0, }; scanf("%d", &T); for (i = 0; i < T; ++i) { int l = 0, ll; int ft = 0, fx = 0, fs = 0, fe = 0; int bi = 0; printf("Case #%d:\n", i + 1); int p; while (1) { int c = getc(stdin); switch (c) { case '<': if (fx == 1) { ECHO(NEWLINE); for (ll = 0; ll < l; ++ll) ECHO(' '); } ++l; ft = 1; ECHO_C; break; case '/': if (ft == 1) { l -= 2; fx = 0; } if (p == '<') { ECHO(BACKSPACE); ECHO(BACKSPACE); ECHO('<'); } ECHO_C; break; case '>': if (p == '/') { ++l; fx = 1; } ft = 0; ECHO_C; ECHO(NEWLINE); for (ll = 0; ll < l; ++ll) ECHO(' '); if (l == 0) fe = 1; break; case NEWLINE: if (fx == 1) { fs = 1; ECHO(' '); } break; case ' ': if (fs == 1) break; ECHO_C; break; default: if (p == '>') fx = 1; ECHO_C; break; } if (c != NEWLINE) p = c; if (fe == 1) break; } } return 0; }