#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<iostream>
using namespace std;
const int maxn=200+10;
char buf[maxn][maxn];
int n;
void dfs(int r,int c)
{
printf("%c(",buf[r][c]);
if(buf[r+1][c]=='|'&&r+1<n)//存在子树
{
int temp=c;
while(buf[r+2][temp-1]=='-'&&temp-1>=0)
temp--;
while(buf[r+3][temp]!='\0'&&buf[r+2][temp]=='-')
{
if(!isspace(buf[r+3][temp]))
{
dfs(r+3,temp);
}
temp++;
}
}
printf(")");
}
void solve()
{
n=0;
while(1)
{
fgets(buf[n],maxn,stdin);
if(buf[n][0]=='#')
break;
else
n++;
}
printf("(11");
if(n)
{
for(int i=0;i<strlen(buf[0]);i++)
if(buf[0][i]!=' ')
{
dfs(0,i);
break;
}
}
printf(")\n");
}
int main()
{
int T;
fgets(buf[0],maxn,stdin);
sscanf(buf[0],"%d",&T);//如果输入中间包含空格,则用fgets,用fgets的时候注意要和sscanf搭配
//scanf("%d",&T); 如果这样写T=1987605466
//cout<<"T:"<<T<<endl;
while(T--)
{
solve();
}
return 0;
}
/*int sscanf(const char *buffer,const char *format,[argument ]...);
buffer:存储的数据。
format:格式控制字符串。
argument: 选择性设定字符串。
sscanf会从buffer里读进数据,依照format的格式将数据写入到argument里。
char *fgets(char *buf, int bufsize, FILE *stream);
*buf: 字符型指针,指向用来存储所得数据的地址。
bufsize: 整型数据,指明存储数据的大小。
*stream: 文件结构体指针,将要读取的文件流。*/
uva10562(dfs+fgets+sscanf)
最新推荐文章于 2019-04-11 17:27:00 发布
