爆零了

P1319 压缩技术

LYH_yes @ 2024-08-05 18:56:06

#include<bits/stdc++.h>
int main()
{
    long long n,a,b,c,s=0;
    scanf("%ld",&n);
    long long str[n*n];
    for(int i=1;i<=n;++i)
    {
        scanf("%ld",&a,&b);
        for(int j=1;j<=a;++j)
        {
            str[++s]=0;
        }
        for(int j=1;j<=b;++j)
        {
            str[++s]=1;
        }
    }
    for(int i=1;i<=n;++i)
    {
        for(int i=1;i<=n;++i)
        {
            printf("%ld",str[i]);
        }
    }
    return 0;
}

by liyuan2023 @ 2024-08-05 19:07:23

@LYH_yes 谁告诉你有n+1个数?


by liyuan2023 @ 2024-08-05 19:14:00

@LYH_yes

#include<bits/stdc++.h>
using namespace std;
int n,a,sum=0,now=1;
int main(){
    cin>>n;
    while(1){
        now^=1;//0,1取反
        cin>>a;
        for(int i=1;i<=a;i++){
            sum++;
            cout<<now;
            if(sum%n==0){//换行处理
                cout<<endl;
            }
        }
        if(sum==n*n){//结束
            break;
        }
    }
    return 0;
}

by happy3h @ 2024-08-10 20:40:00


#include<iostream>
using namespace std;
int main(){
    int n,x,cnt = 0;
    cin>>n;
    int flag = 0;
    int  k = 0;
    while(cnt!=n*n){
        cin>>x;
        cnt+=x;

        for(int i=1;i<=x;i++){
            k++;
            cout<<flag;
            if(k%n==0){
                cout<<endl;
            }
        }
        if(flag == 0){
            flag = 1;
        }
        else{
            flag = 0;
        }
    }
}```
提供一个简单一点的解法

|