uva 10562 Undraw the Trees
来源:互联网 发布:fifo算法c语言实现 编辑:程序博客网 时间:2024/05/22 06:50
题目:Undraw the Trees
题意:给一棵看起来是树的树,要求用括号的表示方法表示。
思路:dfs求解。
注意:
1、uva不能用gets。
2、可能会有一颗空数的情况。
代码:
#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<map>#include<vector>using namespace std;char tree[205][205];int n=0;bool istrue(char x){if(x=='\0'||x=='\n'||x=='\r'||x==' '||x=='#'||x=='-'||x=='|')return false;return true;}void dfs(int row,int col){printf("%c(",tree[row][col]);if(tree[row+1][col]=='|'){int l=0,r=199;for(int i=col-1;i>=0;i--){if(tree[row+2][i]==' '||tree[row+2][i]=='\n'||tree[row+2][i]=='\r'){l=i+1;break;}}for(int i=col+1;i<200;i++){if(tree[row+2][i]==' '||tree[row+2][i]=='\n'||tree[row+2][i]=='\r'){r=i-1;break;}}for(int i=l;i<=r;i++){if(istrue(tree[row+3][i])) dfs(row+3,i);}}printf(")");}int main() {int T;scanf("%d",&T);getchar();while(T--){memset(tree,' ',sizeof(tree));n=-1;while(fgets(tree[++n],201,stdin)&&tree[n][0]!='#');n--;if(n==-1){printf("()\n");continue;}printf("(");for(int i=0;i<200;i++){if(istrue(tree[0][i])){dfs(0,i);break;}}printf(")\n");}return 0;}
阅读全文
2 0
- 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
- uva 10562 Undraw the Trees
- UVA - 10562 Undraw the Trees
- kvm虚拟机挂载lvm卷
- 单链表的基本操作
- MySQL—索引与优化
- 矩阵相乘
- [NOIP2013]货车运输
- uva 10562 Undraw the Trees
- c#自定义可拖动变形控件
- SV 语法自测程序
- TensorFlow 之卷积神经网络一般过程
- 排序算法
- 文理分班
- HDOJ 2141 Can you find it?(二分搜索的优化+总结)
- v-for
- PyQT4编程实例之小财务软件