yukicoder No.116 門松列(1)

Problem

No.116 門松列(1) - yukicoder

Code

    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;
        }
    }
Remove all ads