首页 > 其他 > 详细

Undraw the Trees UVA - 10562

时间:2020-02-09 18:48:18      阅读:65      评论:0      收藏:0      [点我收藏+]

链接:https://vjudge.net/problem/UVA-10562

又被坑死在了字符串的‘\0‘上。。这道题是‘-’的覆盖范围有可能超出下一行字符串的长度,初始化为0后要判断是否为‘\0‘。同时中间还忘记判断了越界。。

以后每次用到C字符串时记得考虑下范围,像用string和数组那样,判断是否越界,在字符串这里就是‘\0‘。不过我老是忘。。

#include <iostream>
#include <cstdio>
#include <cstring>
//#define fre
//#define DEBUG
using namespace std;
char tr[205][205];
int dn;
void draw(int l, int r, int d)
{
    for (int i = l; i <= r; ++i)
    {
        if (tr[d][i] != \0 && tr[d][i] !=   && tr[d][i] != - && tr[d][i] != | && tr[d][i] != # && tr[d][i] != \r && tr[d][i] != \n) //555
        {
            printf("%c(", tr[d][i]);
            if (d + 3 < dn && tr[d + 1][i] == |)
            {
                int nl = i, nr = i;
                while (nl >= 1 && tr[d + 2][nl - 1] == -) nl--; //555
                while (tr[d + 2][nr + 1] == -) nr++;
                draw(nl, nr, d + 3);
            }
            putchar());
        }
    }
}

int main()
{
    #ifdef fre
    freopen("in.in", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int n; scanf("%d", &n);
    fgets(tr[0], 3, stdin);
    while (n--)
    {
        dn = 0;
        memset(tr, 0, sizeof(tr));
        while (fgets(tr[dn], 205, stdin) && tr[dn][0] != #) ++dn;
        putchar(();
        if (dn) draw(0, strlen(tr[0]) - 1, 0);
        puts(")");
    }
}

 

Undraw the Trees UVA - 10562

原文:https://www.cnblogs.com/jionkitten/p/12287836.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!