ACM篇:UVa 10562 -- Undraw the Trees
2017-01-11 12:52
381 查看
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <cstring> #include <sstream> #include <cmath> #include <cctype> using namespace std; const int MAX = 200; int n; char s[MAX+2][MAX+2]; bool is_printable(char ch) { return !(ch == '|' || ch == '-' || ch == ' ' || ch == '#' || ch == '\0' || ch == '\n'); } int read_tree() { memset(s, 0, sizeof(s)); n = 0; while (gets(s ) && strcmp(s , "#")) n++; } void print_tree(int r, int lo, int hi) { putchar('('); for (int j = lo; j <= hi; j++) { if (is_printable(s[r][j])) { putcha 926c r(s[r][j]); if (s[r+1][j] == '|') { int begin = j; int end = j; while (begin && s[r+2][begin-1] == '-') begin--; while (s[r+2][end+1] == '-') end++; print_tree(r+3, begin, end); } else printf("()"); } } putchar(')'); } int main() { int T; scanf("%d\n", &T); while (T-- > 0) { read_tree(); print_tree(0, 0, strlen(s[0])-1); putchar('\n'); } return 0; }
相关文章推荐
- uva 10562 - Undraw the Trees
- uva10562 Undraw-the-Trees 字符题处理 递归
- 【例题 6-17 UVa 10562】Undraw the Trees
- UVa 10562 - Undraw the Trees
- UVa 10562 - Undraw the Trees
- uva 10562 - Undraw the Trees
- 例题6-17 UVa10562 Undraw the Trees(树)
- Uva10562 Undraw the Trees 【递归建树】【例题6-17】
- uva 10562 Undraw the trees(看图写树)
- uva 10562 undraw the trees(烂题) ——yhx
- Uva10562——Undraw the Trees
- UVA 10562 - Undraw the Trees
- UVA - 10562 Undraw the Trees
- UVa10562 Undraw the Trees
- Uva - 10562 - Undraw the Trees
- UVA10562- Undraw the Trees
- UVA 10562 - Undraw the Trees
- uva 10562 Undraw the Trees
- uva10562 Undraw the Trees
- Uva - 10562 - Undraw the Trees