【例题 6-17 UVa 10562】Undraw the Trees
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
模拟+递归
【代码】
#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的更多相关文章
- UVa 10562 Undraw the Trees 看图写树
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将 ...
- UVa 10562 Undraw the Trees(递归遍历)
题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect ...
- uva 10562 undraw the trees(烂题) ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wA ...
- UVa 10562 Undraw the Trees
题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #in ...
- UVA - 10562 Undraw the Trees(多叉树的dfs)
题意:将多叉树转化为括号表示法. 分析:gets读取,dfs就好了.注意,样例中一行的最后一个字母后是没有空格的. #pragma comment(linker, "/STACK:10240 ...
- [DFS遍历图]UVA10562 Undraw the Trees
传送门: 1. UVA - 10562 2. Vjudge [看图写树] 将题目中给出的树改写为 括号表示法 即 (ROOT (SON1(...) (SON2(...)...(SONn(... ...
- UVa10562 Undraw the Trees
注意点: 空树情况处理. >= && buf[r+][i-]=='-') i--; #include<cstdio> #include<cstring> ...
- UVa 10562 (特殊的输入处理方式) Undraw the Trees
题意: 给出一个二维字符数组,它代表了一棵树.然后将这棵树转化为括号表示法(以递归的形式). 分析: 这道题最大的特色就是对数据的处理方式,里面用到了一个 fgets() 函数,这个函数的功能有点像c ...
- 【紫书】Undraw the Trees UVA - 10562 递归,字符串
题意:给你画了一颗树,你要把它的前序输出. 题解:读进到二维数组.边解析边输出. 坑:少打了个-1. #define _CRT_SECURE_NO_WARNINGS #include<cstri ...
随机推荐
- 零基础学python-7.6 字符串格式化表达式
字符串格式化同意在一个单个的步骤中对一个字符串运行多个特定类型的替换 特别是给用户提示的时候,格式化很方便 实现方法: 1.格式化表达式,类似于c语音的printf 在表达式中,我们使用%二进制操作符 ...
- es62
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js--09定时器
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- amaze ui响应式辅助
amaze ui响应式辅助 响应式辅助 就是不同的显示屏幕,或者手机的横竖屏,你可以控制栏目的显影,还是挺有帮助的 视口大小 .am-[show|hide]-[sm|md|lg][-up|-down| ...
- 1.Maven之(一)Maven是什么
转自:https://blog.csdn.net/xhxmister/article/details/79409208 首先,Maven的正确发音是[ˈmevən],而不是“马瘟”以及其他什么瘟.Ma ...
- newgrp---将当前登录用户临时加入到已有的组中
Linux中的newgrp命令主要是将当前登录用户临时加入到已有的组中,用法如下: [linuxidc@localhost etc]$ newgrp grptest 上面命令的含义是将用户linuxi ...
- Mysql学习总结(16)——Mysql之数据库设计规范
一.三大范式 1.第一范式:消除一个字段包含多个数据库值,消除一个记录包含重复的组(单独的一列包含多个项目),即可满足1NF. 2.第二范式:消除部分依赖性即可转化为2NF.部分依赖性表示一个记录中包 ...
- POJ——T 2406 Power Strings
http://poj.org/problem?id=2406 Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 50627 ...
- C++怎么访问私有变量和函数
用指针呀,了解C++内存结构的话. 1. 对于私有成员变量,可以用指针来访问. 2. 对于虚函数,也可以用指针来访问. 3. 另外,对于私有成员,如果摸不准地址构造,可以先构造一个结构相似的类,然后增 ...
- Android-Volley网络通信框架(二次封装数据请求和图片请求(包含处理请求队列和图片缓存))
1.回想 上篇 使用 Volley 的 JsonObjectRequest 和 ImageLoader 写了 电影列表的样例 2.重点 (1)封装Volley 内部 请求 类(请求队列,数据请求,图片 ...