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 ...
随机推荐
- 在form表单里上传图片
需要上传多个图片分别上传,本来提供的工具类里上传一张可以form表单对象实现 后台用MultipartFile file var formdata = new FormData($("#in ...
- Python 的第一个小程序
F盘 新建文本文档 hello.txt 内容为: print("hello world! hello 2018!"); 打开CMD cd c:\ ...
- Android:JNI强化训练
一.前言 Java本机接口(Java Native Interface (JNI))是本机编程接口,它是JDK的一部分,JNI它提供了若干的API,实现了和Java和其他通信(主要是C&C++ ...
- Exploit-Exercises nebule 旅行日志(二)
接着上次的路程继续在ubuntu下对漏洞的探索练习,这次是level01了 先看下level01的问题描述: 目标还是要能运行getflag这个可执行的程序,但如果直接运行是不行的,会提示: getf ...
- jsp页面传中文到后台乱码怎么办?
一般从前台传值到后腰如果传的值是中文的话,又不用post传值方式,到后台显示会显示成乱码的形式.所以以下方法亲测有效防止乱码. 前台jsp页面: var taskTitle = $('#taskTit ...
- Linux相关问题总结
1.linux没有ifconfig命令 可以使用以下命令查询ip地址: ip addr show ifconfig命令在net-tools工具里,安装命令: yum install net-tools
- Linux集群架构(二)
Linux集群架构(二) 目录 八.LVS DR模式搭建 九.keepalived + LVS 十.扩展 八.LVS DR模式搭建 1.实验环境: 四台机器: client: 10.0.1.50 Di ...
- 策略模式在ThreadpoolExecutor中的应用
偶然读到ThreadpoolExecutor的源码,发现里面使用到了策略模式,抓出来和大家分享下: 感兴趣的朋友们可以读读 ThreadPoolExecutor的源码: public void set ...
- Python_day1 Learning record
Python Day1 Learning record(python第一天学习记录) 一.ptyhon安装 windows .下载安装包 https://www.python.org/download ...
- C#ATM
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...