求求大佬帮我看看有什么问题,谢谢!!

P1320 压缩技术(续集版)

feifei3474638569 @ 2024-03-11 21:18:34

#include<stdio.h>
int main()
{
    char ret;
    char ch[1000] = { '\0' };
    int i = 0;
    int cnt = 0;
    while ((ret = getchar()) != '\n')//读入第一行
    {
        ch[i] = ret;
        i++;
    }
    cnt = i;//记录N
    int temp = cnt;
    while (cnt != 1)//读入剩下的行
    {
        if ((ret = getchar()) != '\n')
        {
            ch[i] = ret;
            i++;
        }
        else
        {
            cnt--;
        }
    }
    printf("%d", temp);
    cnt = i;//i=N*N
    int cnt1 = 1;
    int sum1 = 0;
    for (i = 0; i < cnt-1; i++)
    {
        if (ch[i] == ch[i + 1])
        {
            cnt1++;
            continue;
        }
        else
        {
            sum1 += cnt1;
            printf(" %d", cnt1);
            cnt1 = 1;
            continue;
        }
    }
    if (sum1 != cnt)//单独补上因没遍历上最后一个元素造成的缺失
    {
        printf(" %d",cnt-sum1);
    }
}

|