洛谷P1319压缩技术 题解

这道题是入门难度的题。特别水。。。QWQ......

#include<bits/stdc++.h>
using namespace std;
int n,sum,a[210*210],top;
int main(){
    scanf("%d",&n);
    while(sum!=n*n) scanf("%d",&a[++top]),sum+=a[top];//使用while循环输入,因为每位压缩码之和为n*n
    int k=1,p=0;//p表示状态(0、1);k表示数组下标
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[k]!=0) printf("%d",p),a[k]--;
            else k++,p=p==1?0:1,printf("%d",p),a[k]--;
        }
        puts("");//帅气的换行
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/yzx1798106406/p/8964441.html