Run Time: 0.030
Ranking (as of 2016-12-26): 6 out of 370
Language: C++
/* UVa 10146 - Dictionary To build using Visual Studio 2012: cl -EHsc -O2 UVa_10146_Dictionary.cpp */ #include <algorithm> #include <cstdio> using namespace std; const int nr_chars_max = 10; const char* spaces[] = { "", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " }; int main() { int nr_cases; scanf("%d", &nr_cases); while (getchar() != '\n') ; char s[nr_chars_max + 1], t[nr_chars_max + 1]; gets(s); while (nr_cases--) { gets(s); puts(s); char *previous = s, *current = t; int nr_spaces = 1; while (gets(current) && current[0]) { int i; for (i = 0; i < nr_spaces; i++) if (!previous[i] || !current[i] || previous[i] != current[i]) break; printf("%s%s\n", spaces[i], current); nr_spaces = i + 1; swap(previous, current); } if (nr_cases) putchar('\n'); } return 0; }
No comments:
Post a Comment