求助,不知道哪里错了

P1319 压缩技术

thliup @ 2023-12-11 12:53:43

#include<iostream>
using namespace std;
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<stdbool.h>
int a[2000001];
int main() {
    int n; cin >> n;
    int t,i,p=0,ans=0,sum=0;int  k = 0;
    while (cin >> t) {
        for (i = 1 + p; i <= t+p; i++) {
            a[i] = k;
        }sum += t;
        if (sum == n * n)
            break;
        p = i;
        k = 1 - k;
    }
    for (int i = 1; i <= n * n; i++) {
        ans++;
        cout << a[i];
        if(ans == 7) {
            cout << endl;
            ans = 0;
        }
    }
    return 0;
}

|