#include <stdio.h> #include <string.h> char buf[2048]; int buf_used; char *read_line() { char *new_data = buf + buf_used; fgets(new_data, sizeof(buf) - buf_used, stdin); for (int i = strlen(new_data) - 1; i >= 0; i--) { if (new_data[i] == '\r' || new_data[i] == '\n') new_data[i] = '\0'; else break; } buf_used += strlen(new_data); return new_data; } int main() { int num_cases; scanf("%d", &num_cases); fgets(buf, sizeof(buf), stdin); for (int i = 0; i < num_cases; i++) { buf[0] = '\0'; buf_used = 0; int elapsed = 0; while (strcmp(read_line(), "END OF CASE") != 0) { elapsed++; char *start = buf, *end; while ((end = strchr(start, ';')) != NULL) { printf("%d: ", elapsed); fwrite(start, 1 + end - start, 1, stdout); printf("\n"); start = end + 1; } if (start != buf) { buf_used -= start - buf; memmove(buf, start, buf_used); } } } return 0; }