Uva10562——Undraw the Trees
上来一看感觉难以下手,仔细想想就是dfs啊!!!!
#include <cstdio>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int n=;
char s[][];
void dfs (int x,int y)
{//x为第几行,y为某一行的第几个
cout<<s[x][y]<<'(';
if(x+<n&&s[x+][y]=='|')//如果有子树,就向下搜
{
int kk=y;
while(kk->=&&s[x+][kk-]=='-')kk--;//找到最左边
while(s[x+][kk]=='-'&&s[x+][kk]!='\0')
{
if(!isspace(s[x+][kk]))
{
dfs(x+,kk);//从父亲到儿子差3行
}
kk++;
} }
cout<<')';
}
int main()
{
int t;
cin>>t;
getchar();
while(t--)
{
n=;
memset(s,,sizeof(s));
while()
{
gets(s[n]);
if(s[n][]=='#'){break;}
n++;
}
int l;
for(l=;l<strlen(s[]);l++){if(!isspace(s[][l]))break;}//找到根节点
cout<<'(';
dfs(,l);
cout<<')';
cout<<endl; }
return ;
}
还是属于水题一类的吧!
Uva10562——Undraw the Trees的更多相关文章
- UVa10562 Undraw the Trees
注意点: 空树情况处理. >= && buf[r+][i-]=='-') i--; #include<cstdio> #include<cstring> ...
- [DFS遍历图]UVA10562 Undraw the Trees
传送门: 1. UVA - 10562 2. Vjudge [看图写树] 将题目中给出的树改写为 括号表示法 即 (ROOT (SON1(...) (SON2(...)...(SONn(... ...
- UVa 10562 Undraw the Trees(递归遍历)
题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...
- 看图写树 (Undraw the Trees UVA - 10562)
题目描述: 原题:https://vjudge.net/problem/UVA-10562 题目思路: 递归找结点 //自己的代码测试过了,一直WA,贴上紫书的代码 AC代码 #include< ...
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
- uva 10562 undraw the trees(烂题) ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...
- UVa 10562 (特殊的输入处理方式) Undraw the Trees
题意: 给出一个二维字符数组,它代表了一棵树.然后将这棵树转化为括号表示法(以递归的形式). 分析: 这道题最大的特色就是对数据的处理方式,里面用到了一个 fgets() 函数,这个函数的功能有点像c ...
- UVa 10562 Undraw the Trees
题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...
- 【紫书】Undraw the Trees UVA - 10562 递归,字符串
题意:给你画了一颗树,你要把它的前序输出. 题解:读进到二维数组.边解析边输出. 坑:少打了个-1. #define _CRT_SECURE_NO_WARNINGS #include<cstri ...
随机推荐
- RPA与AI_新技术能给企业业务流程带来怎样的价值?
RPA助力于流程自动化蜕变 RPA是Robotic Process Automation的缩写,意为: 将机器人作为虚拟劳动力,依照预先设定的程序与现有用户系统进行交互并完成设定好的任务流程.RPA可 ...
- Oracle 11g OGG 修改 trail 文件大小
OGG 修改 trail 文件大小 2018-06-11 15:14 380 0 原创 GoldenGate 本文链接:https://www.cndba.cn/leo1990/article/285 ...
- Python-接口自动化(五)
python基础知识(五) (六)类与对象 类:某一类具有共同属性和特性的事物或者说是一个抽象的描述,比如说大佬类,你就是大佬类里面具体的一个实例.类一般包含属性和方法 (1)类的语法: class ...
- hosts文件被修改后的惨案
在公司MAC电脑上/etc/hosts中尝试反向解析一个ip到localhost, 即:xxx.xxx.xxx.xxx localhost 然后发现tomcat起不来;
- rnn应用
Weather Recognition plays an important role in our daily lives and many computer vision applications ...
- 【leetcode198 解题思路】动态规划
动态规划 https://blog.csdn.net/so_geili/article/details/53639920 最长公共子序列 https://blog.csdn.net/so_geili/ ...
- YYY0.1YYY
XXX0.2XXXZZZ目前提供免费下载和自动更新功能,由于自己的时间有限,就我一个开发,后期持续更新在线听歌.mp4转mp3.高音质下载.全球dj网站免费下载功能!ZZZ
- python "import this"
The Zen of Python, by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Simp ...
- Fiddle手机抓包
Fiddler是一个http调试代理,它能 够记录所有的你电脑和互联网之间的http通讯,Fiddler 可以也可以让你检查所有的http通讯,设置断点,以及Fiddle 所有的“进出”的数据(指co ...
- JAVA8集合之List
目录: 一.ArrayList概述 二.ArrayList的实现 1)成员变量 2)构造方法 3)元素添加 4)元素删除 5)元素修改 6)集合容量调整 7)集合转数组 三.总结 一.ArrayLis ...