求帮助 0昏

P1320 压缩技术(续集版)

SnowZ @ 2024-09-29 09:15:18

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char text[40000] = "", in[200];
    scanf("%s",in);
    int n;
    n = strlen(in);
    printf("%d ",n);
    strcat(text, in);
    for(int i = 1; i < n; i++){
        scanf("%s",in);
        strcat(text, in);
    }
    int cnt = 1;
    for(int i = 0; i <= strlen(text) - 1; i++){
        if(text[i] == text[i + 1]) cnt++;
        else {
            printf("%d ",cnt);
            cnt = 1;
        }
    }
    return 0;
}

by zhangcm0x3f3f3f @ 2024-10-11 21:39:14

特判开头就是1的情况,在int cnt = 1;后加上 if(text[0]=='1')cout<<0<<" ";


|