样例过了,但是0分,有没有佬救一下

P1320 压缩技术(续集版)

XTTian @ 2023-11-29 11:06:09

#include <iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
int main()
{
    vector<int> arr;
    char ch = 0;
    int n = 0, count = 0;
    while ((ch = getchar()) != '\n')
    {
        arr.push_back(ch - '0');
        n++;
    }
    for (int i = 0; i < n - 1; i++)
        while ((ch = getchar()) != '\n')
            arr.push_back(ch - '0');
    cout << n;
    arr.push_back(2);
    for (int i = 0; i < n * n; i++)
    {
        if (arr[i] == 0)
        {
            count++;
            if (arr[i + 1] == 1)
            {
                cout << " " << count;
                count = 0;
            }
            else if (arr[i + 1] == 2)
            {
                cout << " " << count;
                return 0; 
            }
        }
        if (arr[i] == 1)
        {
            count++;
            if (arr[i + 1] == 0)
            {
                cout << " " << count;
                count = 0;
            }
            else if (arr[i + 1] == 2)
            {
                cout <<  " " << count;
                return 0;
            }
        }
    }
    return 0;
}

by lyh227 @ 2023-11-29 13:07:53

@XTTian

当开头没有0时,要先输出有0个0


|