UVa 10562 - Undraw the Trees ( DFS )
2018-03-06 12:43
501 查看
题意
看图写树思路
DFS递归AC代码
(学习紫书)#include <iostream> #include <cstdio> #include <cstring> #include <cctype> using namespace std; const int maxn = 200 + 10; char tre[maxn][maxn]; int n; void DFS(int x, int y) { printf("%c(", tre[x][y]); if( x+1<n && tre[x+1][y] == '|') { int i = y; while(i-1 >= 0 && tre[x+2][i-1] == '-') i--; while(tre[x+2][i] == '-' && tre[x+3][i] != '\0'){ if(!isspace(tre[x+3][i])) DFS(x+3, i); i++; } } printf(")"); } void solve(); int main() { int T; scanf("%d",&T); getchar(); while(T--) solve(); return 0; } void solve() { n = 0; for(;;){ fgets( tre , maxn, stdin ); if( tre [0] == '#' ) break; else n++; } printf("("); if( n ){ for( int i = 0; i < strlen(tre[0]); i++ ){ if(tre[0][i] != ' '){ DFS(0, i); break; } } } printf(")\n"); }
相关文章推荐
- 【例题 6-17 UVa 10562】Undraw the Trees
- uva 10562 Undraw the Trees
- UVA - 10562 Undraw the Trees(看图建树)
- Uva10562——Undraw the Trees
- uva 10562 - Undraw the Trees
- UVA 10562 Undraw the Trees
- uva 10562 - Undraw the Trees
- uva10562 Undraw the Trees (不定叉树重建)
- uva 10562 Undraw the Trees(数据处理+建树)
- UVa 10562 - Undraw the Trees
- Undraw the Trees UVA10562
- UVA - 10562 Undraw the Trees
- UVA 10562 Undraw the Trees
- UVa 10562 Undraw the Trees (二叉树先序遍历)
- Uva - 10562 - Undraw the Trees
- UVa 10562 - Undraw the Trees
- UVA10562 - Undraw the Trees
- UVA - 10562 Undraw the Trees
- uva 10562 undraw the trees(烂题) ——yhx