結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー htensai
提出日時 2020-02-17 12:31:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,915 ms / 2,500 ms
コード長 661 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 73,984 KB
実行使用メモリ 41,340 KB
最終ジャッジ日時 2024-10-06 14:54:41
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		for (int i = n - 1; i >= 0; i--) {
		    for (int j = 0; j < i; j++) {
		        if (arr[j] > arr[j + 1]) {
		            count++;
		            int tmp = arr[j];
		            arr[j] = arr[j + 1];
		            arr[j + 1] = tmp;
		        }
		    }
		}
		System.out.println(count);
    }
}
0