题目:https://vjudge.net/problem/UVA-10562
#include<iostream>
#include<cstdio>
#include<cstring>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 200 + 5;
char buff[maxn][maxn];
int n;
void DFS(int r, int c)
{
cout << buff[r][c] << "(";
if (r + 1 < n && buff[r + 1][c] == '|')
{
int i = c;
while (i - 1 >= 0 && buff[r + 2][i-1] == '-') i--;
while (buff[r + 2][i] == '-' && buff[r + 3][i] != '\0')
{
if (!isspace(buff[r + 3][i]))
DFS(r + 3, i);
i++;
}
}
cout << ")";
}
int main()
{
int kcase;
cin >> kcase;
getchar();
while (kcase--)
{
n = 0;
while (1)
{
fgets(buff[n], maxn, stdin);
if (buff[n][0] == '#') break;
else n++;
}
cout << "(";
if (n)
{
for (int i = 0; i < strlen(buff[0]); i++)
{
if (buff[0][i] != ' ') { DFS(0, i); break; }
}
}
cout << ")" << endl;
}
return 0;
}