結果

問題 No.116 門松列(1)
ユーザー fkwnw3_1243
提出日時 2017-04-29 07:37:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 54 ms / 5,000 ms
コード長 1,168 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 77,788 KB
実行使用メモリ 37,300 KB
最終ジャッジ日時 2024-06-25 01:28:13
合計ジャッジ時間 4,453 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        int kadomatu = 0;
        int N = Integer.parseInt(reader.readLine());
        String[] inputs = reader.readLine().split(" ");
        for (int i = 0; i < N - 2; i++) {
            int a = Integer.parseInt(inputs[i]);
            int b = Integer.parseInt(inputs[i + 1]);
            int c = Integer.parseInt(inputs[i + 2]);
            if (isKadomatu(a, b, c)) {
                kadomatu += 1;
            }
        }
        System.out.println(kadomatu);
    }

    private static boolean isKadomatu(int a, int b, int c) {

        if (a != b && a != c && b != c) {
            int[] sequence = new int[]{a,b,c};
            Arrays.sort(sequence);
            if (b != sequence[1] ) {
                return true;
            } else {
                return false;
            }

        } else {
            return false;
        }
    }
}
0