题意:

  将树的关系用字符串的形式给出

分析:

  直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行。

代码:

  1. #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    const int maxn=210;
    int n;
    char a[maxn][maxn];
    void dfs(int r,int c)
    {
    printf("%c(",a[r][c]);
    if(r+1<n&&a[r+1][c]=='|')
    {
    int i=c;
    while(i-1>=0&&a[r+2][i-1]=='-')
    i--;
    while(a[r+2][i]=='-'&&a[r+3][i]!='\0')
    {
    if(!isspace(a[r+3][i]))
    dfs(r+3,i);
    i++;
    }
    }
    printf(")");
    }
    void solve()
    {
    n=0;
    while(1)
    {
    gets(a[n]);
    if(a[n][0]=='#')
    break;
    else
    n++;
    }
    printf("(");
    if(n)
    {
    for(int i=0;i<=strlen(a[0]);i++)
    {
    if(a[0][i]!=' ')
    {
    dfs(0,i);
    break;
    }
    }
    }
    printf(")\n");
    }
    int main()
    {
    int T;
    scanf("%d",&T);
    getchar();
    while(T--)
    {
    solve();
    }
    }

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)

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

  5. UVa10562 Undraw the Trees

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

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

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

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

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

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

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

  9. 看图写树 (Undraw the Trees UVA - 10562)

    题目描述: 原题:https://vjudge.net/problem/UVA-10562 题目思路: 递归找结点 //自己的代码测试过了,一直WA,贴上紫书的代码 AC代码 #include< ...

随机推荐

  1. MFC学习之程序执行过程梳理

    *首先利用全局变量对象theApp启动应用程序.这是由于这个全局对象,基类CWinApp中this的指针才干指向这个对象.假设没有这个全局对象,程序在编译时不会出错,但在执行时就会出错. *调用全局应 ...

  2. sharepreference实现记住password功能

        SharePreference是用于保存数据用的.主要调用Context.getSharePreferences(String name, int mode)方法来得到SharePrefere ...

  3. Vlc基础数据结构记录

    1.  Vlc基础数据结构 hongxianzhao@hotmail.com 1.1  基础数据结构 struct vlc_object_t,相关文件为src\misc\objects.c. 定义为: ...

  4. Sublime Text插件FileHeader实践

    FileHeader是一个文件模板插件,可以定制各种文件模板和文件头部信息,保存时可以自动更新文件的修改时间.在多人开发中这个功能相当实用. 具体介绍我就不细说了,主要是分享一下在使用FileHead ...

  5. 跨服务器的sql使用

    由于想从别的服务器上的数据库导入一些数据过来 经网上查阅,得到 select * from openrowset( 'SQLOLEDB', '服务器名字'; '用户名'; '密码',数据库名字.dbo ...

  6. Information seeking letter, hard copy version

    23 Roanoke Street Blacksburg, VA 24060 (540) 555-1123 K.Walker@vt.edu October 23, 20XY Mr. James G. ...

  7. hdu3123GCC

    Problem Description The GNU Compiler Collection (usually shortened to GCC) is a compiler system prod ...

  8. Android 轮询之 Service + AlarmManager+Thread (转)

    android中涉及到将服务器中数据变化信息通知用户一般有两种办法,推送和轮询. 消息推送是服务端主动发消息给客户端,因为第一时间知道数据发生变化的是服务器自己,所以推送的优势是实时性高.但服务器主动 ...

  9. 克隆虚拟机后修改MAC地址

    克隆后的主机找不到eth0 修改 /etc/udev/rules.d/70-persistent-net.rules 删除原eth0的信息,将eth1的name改为eth0 修改 /etc/sysco ...

  10. Python之路第六天,基础(8)-反射

    反射 利用字符串的形式去对象(模块)中操作(寻找/检查/删除/设置)成员(函数). Python中反射用到的4个内置函数:getattr(),setattr(),hasattr(),delattr() ...