为什么???样例都对的,交上去全错,求助大佬。

P1319 压缩技术

jh2023 @ 2023-09-02 19:54:13

为什么???样例都对的,交上去全错,求助大佬。

#include <bits/stdc++.h>
using namespace std;
int a[210];
int main() {
    int n;
    cin >> n;
    int user;
    int total = 0;
    int count = 0;
    int num = 0;
    int sum = 0;
    while (total < n * n) {
        cin >> user;
        total += user;
        a[++num] = user;
    }
    /*cout << endl << endl;
    cout << "!";
    for (int i = 1; i <= num; i++) {
        cout << a[i] << endl;
    }
    cout << endl << endl;*/
    for (int i = 1; i <= num; i++) {
        if (i % 2 == 0) {
            for (int j = 1; j <= a[i]; j++) {
                cout << 1;
                sum++;
                if (sum == 49) {
                    break;
                }
                if (sum % 7 == 0) {
                    cout << endl;
                }
            }
        }
        else if (i % 2 != 0) {
            for (int j = 1; j <= a[i]; j++) {
                cout << 0;
                sum++;
                if (sum == 49) {
                    break;
                }
                if (sum % 7 == 0) {
                    cout << endl;
                }

            }
        }
    }
    return 0;
}

by 洛天依_ @ 2023-09-02 20:00:40

if (sum == 49) N又不会一定是7


|