帮帮孩子吧

P1320 压缩技术(续集版)

zhenghaoHoney @ 2024-10-06 09:34:05


#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

char flag='0';
string a,k;
int n,sum;
int main(){
    while(cin>>a)
    {
        k+=a;
        n++;
    }
    cout<<n<<endl;
    for(int i=0;i<k.size();i++)
    {
        if(k[i]==flag)
        {
            sum++;
        }
        else
        {
            flag=(flag=='0'?flag='1':flag='0');
            cout<<sum<<" ";
            sum=1;
        }
    }
    cout<<sum; 
    return 0;
}

by csxx601cjy @ 2024-10-06 09:35:16

#include<bits/stdc++.h>
using namespace std;
int a[40010],len=0,p=0,cnt=0;
char c=' ';
int main(){
    while(scanf("%c",&c)!=EOF)
        if(c=='0'||c=='1')
            a[len++]=c-'0';
    cout<<sqrt(len)<<' ';
    for(int i=0;i<len;i++){
        if(a[i]==p)cnt++;
        else cout<<cnt<<' ',cnt=1,p=(p+1)%2;
    }
    cout<<cnt;
    return 0;
}

by xQWQx @ 2024-10-06 09:35:51

@zhenghaoHoney

题目叫你换行了吗?????

#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

char flag='0';
string a,k;
int n,sum;
int main(){
    while(cin>>a)
    {
        k+=a;
        n++;
    }
    cout<<n<<" ";//换什么行???
    for(int i=0;i<k.size();i++)
    {
        if(k[i]==flag)
        {
            sum++;
        }
        else
        {
            flag=(flag=='0'?flag='1':flag='0');
            cout<<sum<<" ";
            sum=1;
        }
    }
    cout<<sum; 
    return 0;
}

|