压缩技术(续集版)求大佬找错

P1320 压缩技术(续集版)

A15836042329 @ 2021-12-14 12:19:19

#include<iostream>
using namespace std;
#include<string.h>
#include<cmath>
int main()
{
    string test, str1;
    int n,l,i,flag,sum=0;
    cin >> str1;
    test = test + str1;
    n = test.length();

    for (i=1;i<n;i++)
    {
        cin >> str1;
        test = test + str1;

    }
    if (test[0]=='0')
    {
        flag = 0;
        //cout << "正确吗" << endl;
        sum++;
    }
    else
    {
        flag = 1;
        sum++;
    }
    cout << n << " ";
    for (i = 1;i < n * n;i++)
    {
        if (test[i] == '0' && flag == 0)
        {
            sum++;
            //cout << "第一个" << i<<endl;
        }
        else
        if (test[i] =='1' && flag == 0)
        {
            cout << sum<<" ";
            sum = 0;
            sum++;
            flag = 1;
        }
        else
        if (test[i] == '1' && flag == 1)
            sum++;
        else
        if (test[i] == '0' && flag == 1)
        {
            cout << sum<<" ";
            sum = 0;
            sum++;
            flag = 0;
        }
    }
    if (sum != 0)
        cout << sum;
    return 0;
}

|