标签:中间 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(")"); } }
标签:中间 puts 初始化 iostream txt fine void ace for
原文地址:https://www.cnblogs.com/jionkitten/p/12287836.html