码迷,mamicode.com
首页 > 其他好文 > 详细

Undraw the Trees UVA - 10562

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

标签:中间   puts   初始化   iostream   txt   fine   void   ace   for   

链接: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

标签:中间   puts   初始化   iostream   txt   fine   void   ace   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!