【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

模拟+递归

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 200; string s[N+10];
int n; bool is(char key){
if (key!='-' && key != '|' && key != ' ' && key != '#') return true;
return false;
} void dfs(int x,int y){
// cout << x <<' '<<y<<endl;
// if (s[x][y]==' ') cout <<"???";
cout <<s[x][y];cout << "(";
if (x+1 < n && s[x+1][y]=='|'){
int l = y,r = y;
if (x+2 < n){
while (l-1 >= 0 && s[x+2][l-1]=='-') l--;
while (r+1 <(int) s[x+2].size() && s[x+2][r+1]=='-') r++;
if (x+3 < n){
for (int i = l;i <= r;i++){
if (i<(int)s[x+3].size() && is(s[x+3][i])) {
dfs(x+3,i);
}
} }
}
}
cout << ")";
} int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
cin.get();
while (T--){
n = 0;
while (getline(cin,s[n])){
if (s[n][0]=='#') break;
// cout << s[n];
// cout <<"size="<<' '<<s[n].size()<<endl;
n++;
}
cout << "(";
if (n>=1){
for (int i = 0;i < (int) s[0].size();i++)
if (is(s[0][i]))
dfs(0,i);
}
cout << ")"<<endl;
} return 0;
}

【例题 6-17 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搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...

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

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

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

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

  7. UVa10562 Undraw the Trees

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

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

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

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

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

随机推荐

  1. hdu5305 Friends(dfs+map/hash)

    题目:pid=5305">http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给定N个人和M条朋友关系,是朋友关系的两个人之间有两种联系 ...

  2. 实用的 Python 包 —— 使用 win32 的剪贴板

    1. usage >> import win32clipboard >> win32clipboard.OpenClipboard() >> win32clipbo ...

  3. 什么是CSS重置,有些什么作用?

    CSS重置是什么? 简单的说就是重置浏览器的CSS默认属性. 为什么要重置它,有什么作用? 因为浏览器的品种很多,每个浏览器的默认样式也是不同的,比如<button>标签,在IE浏览器.F ...

  4. C#List<string>和string[]之间的相互转换

     一.LIST概述 所属命名空间:System.Collections.Generic      public class List<T> : IList<T>, IColle ...

  5. spring mvc 接收ajax 复杂结构数据

    1. 前段将要发送的信息转换成json字符串 2. spring mvc 使用 @RequestBody 来接收字符串,然后解析

  6. 如何优雅的写UI——(4)选项卡美化

    现在做出来的选项卡实在太丑的,咱们怎么把他弄得好看一点呢 tabctrl是可以添加icon图标的,那派生与tabctrl的mfctabctrl肯定也能添加图标,他们两个添加图标的原理一样,但是还是有点 ...

  7. 细说 iOS 消息推送

    APNS的推送机制 与Android上我们自己实现的推送服务不一样,Apple对设备的控制很严格.消息推送的流程必需要经过APNs: 这里 Provider 是指某个应用的Developer,当然假设 ...

  8. Linux下读写芯片的I2C寄存器

    要想在Linux下读写芯片的I2C寄存器,一般需要在Linux编写一份该芯片的I2C驱动,关于Linux下如何编写I2C驱动,前一篇文章<手把手教你写Linux I2C设备驱动>已经做了初 ...

  9. CentOS7下简单安装python3.7.0步骤

    一.安装编译工具 #yum -y install gcc #yum -y groupinstall "Development tools" #yum -y install zlib ...

  10. swift -结构体

    // // main.swift // Struct-Demo-05 // import Foundation println("结构体測试!") //结构体和C语言的结构体不同 ...