求助看代码错误

P1320 压缩技术(续集版)

MRZYF @ 2022-12-31 17:15:02

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    char a[201][201] = {0};
    int num = 1;
    int ss[200] = {0};
    int flag = 0;
    for (int i = 0; i < num; i++)
    {
        scanf("%s", a[i]);
        if (flag == 0)
            num = strlen(a[i]);
        flag++;
    }
    printf("%d ", num);
    int k = 0;
    ss[0] = 1;
    for (int i = 0; i < num; i++)
    {
        for (int j = 0; j < num; j++)
        {

            if ((j != num - 1) && (a[i][j] == a[i][j + 1]))
            {
                ss[k]++;
            }
            else if (i == num - 1 && j == num - 1)
            {
            }
            else if (i != num - 1 && j == num - 1 && a[i][j] == a[i + 1][0])
            {
                ss[k]++;
            }
            else
            {
                k++;
                ss[k]++;
            }
        }
    }

    for (int i = 0; i <= k; i++)
    {
        printf("%d ", ss[i]);
    }
}

输出结果我试了几个没问题,为什么就是不对


by Payton123 @ 2023-01-06 00:49:21

可能是输入吧,我之前用cin.get()|getchar()|scanf()都全部WA,后面改为了每一行使用string接收,一下子就AC了,您不妨修改一下输入方式?


|