結果

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

ソースコード

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 middle;
            if (a <= b && b <= c) {
                middle = b;
            } else if (b <= a && a <= c) {
                middle = a;
            } else {
                middle = c;
            }

            if (middle == a || middle == c) {
                return true;

            } else {
                return false;
            }

        } else {
            return false;
        }
    }
}
0