用计数的思想做的

P1320 压缩技术(续集版)

fate159 @ 2023-06-07 19:18:40

用计数的思想做的

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,s1="";
    int n,l=0,y=0,h=0,a[2000]={0};
    while(cin>>s){
        n=s.size();
        s1=s1+s;
    }
    s1=s1+"a"; 
    int n1=s1.size();
    for(int i=0;i<n1;){
        while(s1[i]=='0'){
            l++;
            i++;
        }
        a[h]=l;
        l=0;
        h=h+1;
        if(s1[i]=='a'){
            break;
        }
        while(s1[i]=='1'){
            y++;
            i++;
        }
        a[h]=y;
        y=0;
        h=h+1;
        if(s1[i]=='a'){
            break;
        }
        }
    cout<<n<<" ";
    for(int i=0;i<h;i++){
        cout<<a[i]<<" ";
    }   
    return 0;
}

by Claire0918 @ 2023-06-07 19:31:37

@fate159 tlqtj?


by fate159 @ 2023-06-07 20:14:49

@Claire0918 ???什么意思


by Claire0918 @ 2023-06-07 20:17:12

@fate159 你的代码是否有问题需要求助?


|