求助:没有使用gets()依然全WA
查看原帖
求助:没有使用gets()依然全WA
463591
秋夜Dx楼主2021/1/19 00:08

求大神解救Orz…… 没有使用gets( ),也没什么特别的地方……就是笨方法,一个字符一个字符地处理,最后输出结果。在本地测试正确,但总是全WA……

#include <cstdio> //P1320 压缩技术(续集版)

int main() {
    int N=0;
    int i=0,i_s=1;
    char ch,last;
    int str[10000]={0};

    while(scanf("%c",&ch)!=EOF)
    {
        if(ch!='\n')
            N++;
        else
        {
            str[0]=N;
            break;
        }
        if(i==0)
        {
            if(ch=='1')
            {
                i++;
                str[i_s]=0;
                i_s++;
                last=ch;
                continue;
            }
            else
            {
                last=ch;
                i++;
                continue;
            }
        }
        else
        {
            if(last==ch)
            {
                i++;
                continue;
            }
            else
            {
                str[i_s]=i;
                i_s++;
                i=1;
                last=ch;
                continue;
            }
        }
    }
    while(scanf("%c",&ch)!=EOF)
    {
        if(ch=='\n')
            continue;
        if(i==0)
        {
            last=ch;
            i++;
            continue;
        }
        else
        {
            if(last==ch)
            {
                i++;
                continue;
            }
            else
            {
                str[i_s]=i;
                i_s++;
                i=1;
                last=ch;
                continue;
            }
        }
    }
    str[i_s]=i;
    for(int j=0;j<i_s;j++)
        printf("%d ",str[j]);
    printf("%d",str[i_s]);
    return 0;
}

2021/1/19 00:08
加载中...