求救,看不出来哪错了,全wa,提示第一行太短?

P1320 压缩技术(续集版)

qwq57qwq @ 2024-12-22 21:53:10

#include<iostream>
#include<string>
using namespace std;

int main()
{
    string a[220];
    int lens = 0;
    for (int i = 0; ; i++)
    {
        cin >> a[i];
        if (i == 0)
        {
            lens = a[0].size();
        }
        if (i == lens - 1)break;
    }
    cout << lens << " ";
    bool flag = 0;
    int cnt = 0;
    for (int i = 0; i < lens; i++)
    {
        for (int j = 0; j < lens; j++)
        {
            if (a[i][j] == flag + '0')
            {
                cnt++;
            }
            else
            {
                cout << cnt << " ";
                cnt = 1;
                flag = !flag;
            }
        }
    }
    return 0;
}

|