求助 一半WA一半RE

P1320 压缩技术(续集版)

anangxu @ 2022-10-06 19:25:34

#include <stdio.h>
char a[205][205] = { 0 };
int main(void)
{
    int i = 1, j = 1;
    while(1)
    {
        a[i][j] = getchar();
        while (a[i][j] == '\n' || a[i][j] == '\r')
        {
            if (i + 1 == j)
                goto ha;
            i++;
            j = 1;
            a[i][j] = getchar();
        }
        j++;
    }
    int n;
ha:
    n = j - 1;
    printf("%d ", n);
    int sum = 0;
    char s = '0';
    for (int x = 1; x <= n; x++)
    {
        for (int y = 1; y <= n; y++)
        {
            if (a[x][y] == s)
            {
                sum++;
            }
            else
            {
                printf("%d ", sum);
                sum = 1;
                s = a[x][y];
            }
        }
    }
    printf("%d", sum);
    return 0;
}

by hjsxhst2022 @ 2022-10-07 12:07:21

@anangxu while(1)会直接跳过,getchar()会读入空格


by Soul_direction @ 2022-10-10 19:32:09

应该是数组长度不够,导致RE,我亲身经历的


|