結果

問題 No.116 門松列(1)
ユーザー rf141
提出日時 2015-08-10 04:25:35
言語 Java
(openjdk 23)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 594 bytes
コンパイル時間 3,732 ms
コンパイル使用メモリ 74,936 KB
実行使用メモリ 54,328 KB
最終ジャッジ日時 2024-06-25 01:09:08
合計ジャッジ時間 8,491 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class kadomatsu{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] k = new int[n];
		for(int i = 0; i < n; i++){
			k[i] = scan.nextInt();
		}
		System.out.println(search(n,k));
	}
	public static int search(int n,int[] k){
		int count=0;
		for(int i = 0; i < n-2; i++){
			int low = k[i];
			int middle = k[i+1];
			int high = k[i+2];
			if(low!=high){
				if(middle > low && middle > high){
					count++;
				}else if(low > middle && middle < high){
					count++;
				}
			}
		}
		return count;
	}
}
0