题意:

  将树的关系用字符串的形式给出

分析:

  直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=210;
int n;
char a[maxn][maxn];
void dfs(int r,int c)
{
printf("%c(",a[r][c]);
if(r+1<n&&a[r+1][c]=='|')
{
int i=c;
while(i-1>=0&&a[r+2][i-1]=='-')
i--;
while(a[r+2][i]=='-'&&a[r+3][i]!='\0')
{
if(!isspace(a[r+3][i]))
dfs(r+3,i);
i++;
}
}
printf(")");
}
void solve()
{
n=0;
while(1)
{
gets(a[n]);
if(a[n][0]=='#')
break;
else
n++;
}
printf("(");
if(n)
{
for(int i=0;i<=strlen(a[0]);i++)
{
if(a[0][i]!=' ')
{
dfs(0,i);
break;
}
}
}
printf(")\n");
}
int main()
{
int T;
scanf("%d",&T);
getchar();
while(T--)
{
solve();
}
}

UVa 10562 Undraw the Trees的更多相关文章

  1. UVa 10562 Undraw the Trees 看图写树

    转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...

  2. UVa 10562 Undraw the Trees(递归遍历)

    题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...

  3. uva 10562 undraw the trees(烂题) ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...

  4. UVA - 10562 Undraw the Trees(多叉树的dfs)

    题意:将多叉树转化为括号表示法. 分析:gets读取,dfs就好了.注意,样例中一行的最后一个字母后是没有空格的. #pragma comment(linker, "/STACK:10240 ...

  5. UVa10562 Undraw the Trees

      注意点: 空树情况处理. >= && buf[r+][i-]=='-') i--; #include<cstdio> #include<cstring> ...

  6. [DFS遍历图]UVA10562 Undraw the Trees

    传送门: 1. UVA - 10562 2. Vjudge [看图写树]     将题目中给出的树改写为 括号表示法 即 (ROOT (SON1(...) (SON2(...)...(SONn(... ...

  7. UVa 10562 (特殊的输入处理方式) Undraw the Trees

    题意: 给出一个二维字符数组,它代表了一棵树.然后将这棵树转化为括号表示法(以递归的形式). 分析: 这道题最大的特色就是对数据的处理方式,里面用到了一个 fgets() 函数,这个函数的功能有点像c ...

  8. 【紫书】Undraw the Trees UVA - 10562 递归,字符串

    题意:给你画了一颗树,你要把它的前序输出. 题解:读进到二维数组.边解析边输出. 坑:少打了个-1. #define _CRT_SECURE_NO_WARNINGS #include<cstri ...

  9. 看图写树 (Undraw the Trees UVA - 10562)

    题目描述: 原题:https://vjudge.net/problem/UVA-10562 题目思路: 递归找结点 //自己的代码测试过了,一直WA,贴上紫书的代码 AC代码 #include< ...

随机推荐

  1. libaio under MIPS architecture /在mips架构下使用的libaio

    First, you can find libaio source in http://libaio.sourcearchive.com/ Second,download the libaio_0.3 ...

  2. LR实战之Discuz开源论坛——登录脚本

    脚本业务流:访问Discuz论坛首页——登录论坛——退出论坛.本次使用LoadRunner11版本. 一.录制脚本注意 1.确保Discuz论坛能在服务器运行正常. 2.录制前先试访问Discuz论坛 ...

  3. heroku

    一个可以在上面部署自己的应用一个共享平台,例如可以部署访问google的代理 地址为:https://www.heroku.com/

  4. css设置

    box-size允许您以特定的方式定义匹配某个区域的特定元素. content-box(默认):宽度和高度分别应用到元素的内容框.在宽度和高度之外绘制元素的内边距和边框.border-box:为元素设 ...

  5. JS知识点概况

    1.什么是JavaScript a)   JavaScript 被设计用来向 HTML 页面添加交互行为. b)   JavaScript 是一种脚本语言(脚本语言是一种轻量级的编程语言). c)   ...

  6. LINQ 操作符

    using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace LinQ ...

  7. Maximum Subarray (JAVA)

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  8. su普通用户切换root用户失败

    http://blog.itpub.net/26432034/viewspace-1688391/ http://blog.csdn.net/zhangdaiscott/article/details ...

  9. 正三角形的外接圆面积,nyoj-274

    正三角形的外接圆面积 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 描述给你正三角形的边长,pi=3.1415926 ,求正三角形的外接圆面积.   输入 只有一组测试数据 ...

  10. 创建以 API 为中心的 Web 应用

    http://www.oschina.net/translate/creating-an-api-centric-web-application?from=20130818 正计划着要开始搞一个新的网 ...