超时了,不知道咋整( ゚д゚)つ

P1319 压缩技术

mmmath3 @ 2024-09-16 14:57:34

#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a,b,c,d,i;
    b=0;
    i,c=1;
    for (i;b<=n*n;i++){
        a=0;
        scanf("%d",&a);
        b = b+a;
        c = 1-c;
        int j=1;
        for (j;j<=a;j++){
            d++;
            printf("%d",c);
            if (d%n == 0)   printf("\n");
        }
    }

     return 0; 
}

by pmkmzfuzsotqotmzs @ 2024-09-16 15:01:06

@mmmath3

#include<iostream>
#include<string>
using namespace std;
int main()
{

    int n,k;
    cin >> n;
    int a=0;
    int b[40001];
    int c=1;
    while (cin >> k)
    {
        for(int i=1;i<=k;i++)
        {
            b[c]=a;
            c++;
        }
        a = !a;
    }
    for(int i=1;i<c;i++)
    {
        cout<<b[i];
        if(i%n==0)
            cout<<endl;
    }
    return 0;
}

by EricWan @ 2024-09-16 15:04:55

@pmkmzfuzsotqotmzs 他让你帮忙改,不是要代码。


by EricWan @ 2024-09-16 15:05:42

@mmmath3 改好了:


#include <stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a,b,c,d = 0,i;
    b=0;
    i,c=1;
    for (i;b<=n*n;i++){
        a=0;
        scanf("%d",&a);
        b = b+a;
        c = 1-c;
        int j=1;
        for (j;j<=a;j++){
            d++;
            printf("%d",c);
            if (d%n == 0)   printf("\n");
        }
      if (b * b >= n) break;
    }
     return 0; 
}

by EricWan @ 2024-09-16 15:06:34

@mmmath3 你的问题:

  1. d 没有初始化

  2. 没有特判输入结束,使得程序一直无法退出

给个关注呗


by mmmath3 @ 2024-09-16 22:42:01

@EricWan 好的好的,谢谢大佬


|