爆零,求助大佬!

P1319 压缩技术

SY_Nightmare @ 2023-01-11 16:22:03

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,s,d=0;
    cin>>n;
    long long a,t=0;
    for(int i=1;i<=203;i++)
    {
        cin>>a;
        t++;
        if(a==0) continue;
        if(t%2==1) s=0;
        else s=1;
        for(int j=1;j<=a;j++)
        {
            cout<<s;
            d++;
            if(d%n==0) cout<<endl;
        }
    } 
    return 0;
}

by OIer_Kevin @ 2023-01-11 16:34:59

#include <bits/stdc++.h>
using namespace std;
int k[205];
int main() {
    int n,s=0,o=0;
    cin>>n;
    for(int i=1; i<=205; i++) {
        if(s>=n*n)break;
        cin>>k[i];
        s=s+k[i];
    }
    for(int i=1; i<=205; i++){
        if(i%2-1==0||i==1){
            for(int j=1; j<=k[i]; j++){
                cout<<0;
                o++;
                if(o%n==0)cout<<endl;
            }
        }
        else {
            for(int u=1; u<=k[i]; u++){
                cout<<1;
                o++;
                if(o%n==0)cout<<endl;
            }
        }
    }
    return 0;
}

by OIer_Kevin @ 2023-01-11 16:35:51

@Hujunyu0511 ,这道题可以用数组


by SY_Nightmare @ 2023-01-12 13:20:05

@ganyudetinali 万分感谢


|