求助!20分 C++

P1320 压缩技术(续集版)

Qianxi_MRD @ 2022-08-26 16:21:00

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
char a[50000];
int main(){
    int i=0;
    while(cin>>a[i]) i++;
    int n;
    n=sqrt(i);
    cout<<n<<" ";
    int one=0,zero=0;
    for(int j=0;j<=i;j++){
        if(a[j]=='\0'){
            if(one!=0) cout<<one;
            if(zero!=0) cout<<zero;
        }
        if(a[j]=='0'){
            if(one!=0) cout<<one<<" ";
            one=0;
            zero++;
        }
        if(a[j]=='1'){
            if(zero!=0) cout<<zero<<" ";
            zero=0;
            one++;
        }
    }
    return 0;
}

by same233 @ 2022-08-26 16:38:37

题目要求先输出0的个数,就是说第一个字符不为0,也要输出0


by Qianxi_MRD @ 2022-08-26 16:46:30

谢谢


|