結果

問題 No.365 ジェンガソート
ユーザー SagToki
提出日時 2018-06-04 13:30:17
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,460 bytes
コンパイル時間 3,691 ms
コンパイル使用メモリ 80,016 KB
実行使用メモリ 80,492 KB
最終ジャッジ日時 2024-06-30 09:35:50
合計ジャッジ時間 11,740 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 7 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.InputMismatchException;

public class JengaSort {
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args){
        int N = Input(1 , 100000);
        ArrayList<Integer> High = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
            High.add(Input(1,N));
        }
        int Result = Processing(N,High);
        System.out.println(Result);
    }
    
    public static int Input(int Min , int Max){
        int Number = scanner.nextInt();
        try{
            if(Number < Min || Number > Max){
                System.out.println(Min + "以上" + Max + "以下で入力してください");
                System.exit(0);
            }
        }catch(InputMismatchException e){
            System.out.println("数字を入力してください");
            System.exit(0);
        }catch(Exception E){
            System.out.println("予期せぬエラーです");
            System.exit(0);
        }
        return Number;
    }
    
    public static int Processing(int N , ArrayList<Integer> High){
        int Count = 0;
        for(int i = 0 ; i < N ; i++){
            for(int j = i + 1 ; j < High.size() ; j++){
                if(High.get(i) > High.get(j)){
                    Count++;
                    High.remove(j);
                    j--;
                }
            }
        }
        return Count;
    }
}
0