真不知道哪里有问题

P1319 压缩技术

lsyleon @ 2023-10-27 09:40:49

#include<iostream>
#include<string>
using namespace std;
//这是洛谷
int main(){
    int arr[40002] = {0};
    int n;
    cin >> n;
    int sum = 0;
    int i = 1;
    while (1) {
        int temp=0;
        cin >> temp;
        sum += temp;
        arr[i] = temp;
        i++;
        if (sum == n * n) { break; }
    }//存储输入

    int flagg = -1;//0或1判断依据
    int jishuqi = 0;//计数器
    int k = 1;//数组下标
    while (1) {
        if (arr[k] == 0) { break; }
        if (flagg< 0) {
            for (int j = 0; j < arr[k]; j++) {
                if (jishuqi == n) {
                    cout << endl;
                    jishuqi = 0;//如果计数器加满n个,换行,清零
                }
                cout << "0";
                jishuqi++;

            }
            flagg *= -1;
            k++;
        }
        else {
            for (int j = 0; j < arr[k]; j++) {
                if (jishuqi == n) {
                    cout << endl;
                    jishuqi = 0;//如果计数器加满七个,换行,清零
                }
                cout << "1";
                jishuqi++;

            }
            flagg *= -1;
            k++;
        }

    }
    return 0;
}

|