请救救孩子吧!

P1320 压缩技术(续集版)

轮回·天照 @ 2021-03-16 21:36:35

#include <bits/stdc++.h>
using namespace std;
string a[10001],s;
int j = 0;
char c = '0';
int main(){
    while(cin >> a[j])
        j++;
    cout << j << " ";
    s = a[0];
    for(int i = 1;i < j;i++)
        s = s + a[i];
    int count = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == c)
            count++;
        else{
            cout << count << " ";
            count = 1;
            c = 1 - c;
        }
    }
    return 0;
}

爆零


by HYdroKomide @ 2021-03-16 21:58:34

#include<iostream>
#include<cmath>
using namespace std;
char a,b='0';
int n,ans[1000001],point=1;
int main(){
    while(cin>>a){
        n++;
        if(a==b)ans[point]++;
        else{
            ans[++point]++;
            b=a;
        }
    }
    cout<<sqrt(n);
    for(int i=1;i<=point;i++)cout<<" "<<ans[i];
    return 0;
}

by HYdroKomide @ 2021-03-16 21:58:56

@轮回·天照 很氵啊


by 轮回·天照 @ 2021-03-19 14:52:57

@Kevin_FOS 能不能修改一下我的代码


by HYdroKomide @ 2021-03-19 16:43:40

#include <bits/stdc++.h>
using namespace std;
string a[10001],s;
int j = 0;
char c = '0';
int main(){
    while(cin >> a[j])
        j++;
    cout << j << " ";
    s = a[0];
    for(int i = 1;i < j;i++)
        s = s + a[i];
    int count = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == c)
            count++;
        else{
            cout << count << " ";
            count = 1;
            //c = 1 - c; 
            if(c == '0')c = '1';//这里因为c是字符,不能直接用1-c 
            else c = '0';
        }
    }
    cout << count << endl;//最后还要再输出一个 
    return 0;
}

错误都写在注释里了。被迫用不适的码风营业qwq

@轮回·天照


by 轮回·天照 @ 2021-03-20 11:03:39

@Kevin_FOS AC 谢谢!


by 轮回·天照 @ 2021-03-20 11:04:46

@Kevin_FOS 另外,<<和=的左右两端加上空格更好看~


|