コレクション(秋2017 JingdongはリクルートZhenti) - この質問はピット入力されています

免責事項:この記事はブロガーオリジナル記事です、続くBY-SAのCC 4.0を著作権契約、複製、元のソースのリンクと、この文を添付してください。
このリンク: https://blog.csdn.net/m1f2c3/article/details/100024379

ここに画像を挿入説明

注意!sc.hasNext(に使用する正しい答えを)!

import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            int m = sc.nextInt();
            Set<Integer> ab = new TreeSet<>();
            for(int i = 0; i < n; ++i) ab.add(sc.nextInt());
            for(int i = 0; i < m; ++i) ab.add(sc.nextInt());
            for(int mem : ab){
                System.out.printf("%d ", mem);
            }
        }

    }
}

ここに画像を挿入説明

あなたはエラーに)(sc.hasNextない場合

import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int m = sc.nextInt();
            Set<Integer> ab = new TreeSet<>();
            for(int i = 0; i < n; ++i) ab.add(sc.nextInt());
            for(int i = 0; i < m; ++i) ab.add(sc.nextInt());
            for(int mem : ab){
                System.out.printf("%d ", mem);
            }

    }
}

ここに画像を挿入説明

このテストは行う入出力ストリームを使用することですか?このテストは本当にアルゴリズムですか?

おすすめ

転載: blog.csdn.net/m1f2c3/article/details/100024379