求助大佬不知道哪里错了,数组,c++

P1319 压缩技术

zhaoanqiEtayo @ 2023-12-30 21:08:28

#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
    int n,map[40000],k[400000];
    cin >> n;
    int t = 0;
    int i = 0;
    for (int p = 0; p < n; p++)
    {
        cin >> k[p];
    }
    int p = 0;
    while (i<=n*n)
    {   
        if (t%2==0)
        {
            for (; i < i+k[p]; i++)
            {
                map[i] = 0;
            }
        }
        else
        {
            for (; i < i+k[p]; i++)
            {
                map[i] = 1;
            }
        }
        t++;
        i++;
        p++;
    }
    int s = 0;
    for (int j = 0; j < n*n; j++)
    {
        cout << map[j];
        s++;
        if (s%n==0)
        {
            cout << endl;
        }
    }
    return 0;
}

by zhutongxuan @ 2024-01-04 19:29:53

t % 2 == 0这种情况应该是1啊,反之才是0,您搞反了


|