求助大佬们,这应该怎么改

P1319 压缩技术

DARK_LIGHT @ 2019-08-11 11:10:15

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int n,a[200+2],tail;
int main()
{
    char p[200+2];
    cin.getline(p,201);
    n=atoi(p);
    for(int i=2;i<strlen(p);++i)
    {
        if(isdigit(p[i]))
        {
            a[tail++]=atoi(p+i);
            while(isdigit(p[i]))++i;
            --i;
        }
    }
    int c=0;
    for(int i=0;i<tail;++i)
    {
        if(i%2)
        {
            for(int j=0;j<a[i];++j)
            {
                if(c==n)
                {
                    cout<<endl;
                    c=0;
                }
                cout<<1;
                c++;
            }
        }else
        {
            for(int j=0;j<a[i];++j)
            {
                if(c==n)
                {
                    cout<<endl;
                    c=0;
                }
                cout<<0;
                c++;
            }
        }
    }
    return 0;
}

by 学而思李老师 @ 2019-08-11 11:14:44

我给你发一下我写的,没有你那么多STL

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
    int a, n, t = 0, i = 0, b, s = 0;
    scanf("%d", &n);
    while(s < n * n){
        scanf("%d", &a);
        i ++;
        for(b = a; b >= 1; b --){
            if(t == n){
                puts("");
                t = 0;
            }
            if(1 & i){
                printf("0");
            } else {
                printf("1");
            }
            t ++;
            s ++;
        }
    }
    puts("");
    return 0;
}

by Kitty5307 @ 2019-08-11 11:17:45

我怎么好像发过这题的题解 。。


by Kitty5307 @ 2019-08-11 11:18:55

这是窝的代码(

#include<bits/stdc++.h>
#define maxn 40010
using namespace std;
int n,a[maxn],f,i,j,s;
int read(){
    int r=0,f=1;
    char c=getchar();
    while((c<'0'||c>'9')&&c!='-')
        c=getchar();
    if(c=='-')
        f=-1,c=getchar();
    while(c<='9'&&c>='0')
        r=r*10+c-'0',c=getchar();
    return r*f;
}
int main(){
    n=read();
    while(s<n*n)
        a[++f]=read(),s+=a[f];
    s=0;
    for(i=1;i<=f;i++){
        if(i%2)
            for(j=1;j<=a[i];j++){
                printf("0");
                s++;
                if(s%n==0)
                    printf("\n");
            }
        else
            for(j=1;j<=a[i];j++){
                printf("1");
                s++;
                if(s%n==0)
                    printf("\n");
            }
    }
    return 0;
}

by DARK_LIGHT @ 2019-08-11 11:20:52

@libeining QWQ是的


by DARK_LIGHT @ 2019-08-11 15:56:40

有没有在在原代码基础上修改一下的QAQ


|