二叉树的先序遍历  这个还是比较简单的 ~~

/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年10月30日 星期三 19时25分21秒
************************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
char tree[300][300]; void dfs(int l, int r, int cur)
{
putchar('(');
for (int i = l; i < r && tree[cur][i]; i++)
if (tree[cur][i] != '#' && tree[cur][i] != ' ')
{
putchar(tree[cur][i]);
if (tree[cur + 1][i] == '|')
{
int le, re;
for (le = i; le > 0 && tree[cur + 2][le] == '-'; le--);
for (re = i; tree[cur + 2][re] == '-'; re++);
dfs(le, re, cur + 3);
}
else
printf("()");
}
putchar(')');
} int main()
{
int t, n;
scanf("%d\n", &t);
while (t--)
{
memset(tree, 0, sizeof(tree));
n = 0;
while (gets(tree[n]) != NULL)
{
if(tree[n][0] == '#')
break;
n++;
}
dfs(0, strlen(tree[0]), 0);
puts("");
}
return 0;
}

uva 10562的更多相关文章

  1. Uva 10562 看图写树

    题目链接:https://uva.onlinejudge.org/external/105/10562.pdf 紫书P170 直接在二维数组上做DFS,用的fgets函数读入数据,比较gets函数安全 ...

  2. UVa 10562看图写树(二叉树遍历)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVa 10562 Undraw the Trees 看图写树

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

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...

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

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

  6. UVa 10562 Undraw the Trees

    题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...

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

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

  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. sql防注入式

    SQL注入式攻击是利用是指利用设计上的漏洞,在目标服务器上运行Sql命令以及进行其他方式的攻击动态生成Sql命令时没有对用户输入的数据进行验证是Sql注入攻击得逞的主要原因.比如: 如果你的查询语句是 ...

  2. linux file命令小记

    在linux中,所有东西都是文件:而且他并没有后缀名这一概念.Linux的扩展名没有太大的意义, file.tar.gz file.tgz file.tar.bz2 file.rar file.gz ...

  3. ArcSDE for oracle10g安装后post的时候出现错误

    The Post Installation Setup can not locate required Oracle files in your path.Check your Oracle inst ...

  4. 【原】GO 语言常见错误

    1. Scan error on column index 4: converting string "" to a int: strconv.ParseInt: parsing ...

  5. C++ sizeof操作符的用法和strlen函数的区别

    摘要:本人首先介绍了C++中sizeof操作符的用法和注意事项,其次对比了和strlen的区别和使用,方便大家在写代码的时候查阅,和面试.笔试的时候复习. 目录: sizeof的用法: sizeof和 ...

  6. zabbix短信网关调用问题总结

    在写调用短信网关的shell脚本的时候,发现了一个百思不得其解的问题,用浏览器访问短信接口地址是可以成功接收到短信的.但在shell 里面调用就报错了!!!在反复测试当中发现,在shell 中对特殊字 ...

  7. c#汉字转为拼音

    using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressi ...

  8. SQL Server 2008 R2密钥序列号

    SQL Server 2008 R2密钥序列号 序列号: 开发版(Developer): PTTFM-X467G-P7RH2-3Q6CG-4DMYB 企业版(Enterprise): JD8Y6-HQ ...

  9. Spark Streaming揭秘 Day30 集群模式下SparkStreaming日志分析

    Spark Streaming揭秘 Day30 集群模式下SparkStreaming日志分析 今天通过集群运行模式观察.研究和透彻的刨析SparkStreaming的日志和web监控台. Day28 ...

  10. 给虚拟机中的CentOS7配置固定ip

    在虚拟机中安装完了CentOS7之后,使用了DHCP来获取ip,vmware的网络连接使用了NAT模式.但是在把Linux设置为固定ip地址后,虚拟机里的linux可以ping通全网段的ip地址,但是 ...