Undraw the Trees 看图写树 UVA 10562 (DFS)
来源:互联网 发布:软件框架设计工具 编辑:程序博客网 时间:2024/06/06 15:48
本题是一道DFS练习题 ,需要注意一些条件的判断如 '\0',n 的值 等等,详情见代码
- #include<cstdio>
- #include<cstring>
- const int maxn=200+10;
- char tree[maxn][maxn];
- int n;
- void dfs(int r,int c){
- printf("%c(",tree[r][c]);
- if(r+1<n &&tree[r+1][c]=='|'){ //有子树
- while(r+2<n && c-1>=0 && tree[r+2][c-1]=='-')c--; //找"---"左边界
- for(int i=c;tree[r+2][i]=='-' ;i++){
- if(tree[r+3][i]!=' ') //tree[r+3][i]!='\0'此判断不能放在此处,因为它是循环判断条件之一,可以放在for循环中做条件,就是放在此处WR了一次
- if( tree[r+3][i]!='\0')
- dfs(r+3,i);
- else break;
- }
- }
- printf(")");
- }
- int main(){
- int T;
- scanf("%d",&T);
- getchar();
- while(T--){
- n=0;
- while(true){
- gets(tree[n]);
- if(tree[n][0]=='#')break;
- n++;
- }
- printf("(");
- if(n) //记得这里判断一下,当时没判断WR了几次
- for(int i=0;i<strlen(tree[0]);i++)
- if(tree[0][i]!=' '){dfs(0,i);break;}
- printf(")\n");
- }
- return 0;
- }
1 0
- Undraw the Trees 看图写树 UVA 10562 (DFS)
- uva 10562 Undraw the trees(看图写树)
- uva 10562 - Undraw the Trees
- uva 10562 - Undraw the Trees
- uva 10562 - Undraw the Trees
- UVa 10562 - Undraw the Trees
- UVA 10562 - Undraw the Trees
- UVA 10562 Undraw the Trees
- uva 10562 - Undraw the Trees
- uva 10562 - Undraw the Trees
- UVa 10562 - Undraw the Trees
- UVA 10562 Undraw the Trees
- UVA - 10562 Undraw the Trees
- uva-10562Undraw the Trees
- UVA 10562 - Undraw the Trees
- UVA - 10562 Undraw the Trees
- UVa 10562 - Undraw the Trees
- Uva - 10562 - Undraw the Trees
- 微信小程序浅析
- 什么是分布式
- C++ 语法实验室之 friend 关键字
- NDK开发入门(一)
- Intent
- Undraw the Trees 看图写树 UVA 10562 (DFS)
- 进制之和 2106
- redis linux 开机自启
- 初识RecyclerView
- kali-linux网络渗透
- 【LeetCode】131. Palindrome Partitioning
- 使用TraceView分析CPU占用-解决ANR笔记
- 欢迎使用CSDN-markdown编辑器
- 线索二叉树(下)