求助0分

P1320 压缩技术(续集版)

bian_cheng123 @ 2024-07-25 15:14:14

#include <bits/stdc++.h>
using namespace std;
int a[40005],cnt;
int main()
{
    char c;
    while(cin >> c){
        a[++cnt] = c - '0';
    }
    int n = sqrt(cnt);
    cout << n << " "; 
    int flag = 0,sum = 0;
    for (int i = 1 ; i <= cnt ; i++)
    {
        if (a[i] == flag) sum++;
        else{
            cout << sum << " ";
            sum = 1;
            flag = !flag;
        }
    }
    return 0;
}

by haha123456 @ 2024-07-31 20:12:25

cout << n << " "; 是干什么的


by haha123456 @ 2024-07-31 20:15:43

你没有输出最后剩下的sum


by bian_cheng123 @ 2024-07-31 21:23:48

谢谢,此帖结


|