测试了好几个例子都过了,一直全re,求助!JAVA

P1319 压缩技术

hyM123hyM @ 2021-02-20 10:26:17


import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int arr[]=new int[100];
        int length=0;
        for(int i=0;i<N*N;i++){
            arr[i]=sc.nextInt();
            if(i%2==0){
                for(int j=1;j<=arr[i];j++){
                    System.out.print("0");
                    length++;
                    if(length==N){
                        System.out.println();
                        length=0;
                    }
                }
            }if(i%2!=0){
                for(int j=1;j<=arr[i];j++){
                    System.out.print("1");
                    length++;
                    if(length==N){
                        System.out.println();
                        length=0;
                    }
                }
            }
        }
    }
}

by ud2_ @ 2021-02-20 10:44:42

@hyM123hyM

i<N*N

哪来那么多数?


by hyM123hyM @ 2021-02-20 11:40:03

@sjx233_ 那像我这么考虑的话,怎么确定后面到底有几个数呢?


by ud2_ @ 2021-02-20 11:52:45

@hyM123hyM

退出循环用 breaklabel;

也可以读一行,然后按空格分割。参考 https://github.com/sjx233/oj-solutions/blob/master/luogu/P1319.js。


|