uva 10562 - Undraw the Trees
来源:互联网 发布:九亭淘宝仓库合租 编辑:程序博客网 时间:2024/05/16 00:01
#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <vector>using namespace std;void dfs(char s[210][210], int x, int y, int dep){ for(int i = y; s[x][i] == '-'; ++i) if(s[x+1][i] != ' ' && s[x+1][i] && s[x+1][i] != '#') { printf("%c(", s[x+1][i]); if( x+2 < dep && s[x+2][i] == '|'){ int j; for(j = i; j&&s[x+3][j-1] == '-'; --j); dfs(s, x+3, j, dep); } printf(")"); } return;}int main(){ int t; scanf("%d", &t); getchar(); while(t--) { char s[210][210]; memset(s, 0, sizeof(s)); int dep = 1; while(gets(s[dep])){ if(s[dep][0] == '#') break; ++dep; } int len = strlen(s[1]); for(int i = 0; i < len; ++i) s[0][i] = '-'; printf("("); dfs(s, 0, 0, dep); printf(")\n"); } return 0;}