結果

問題 No.116 門松列(1)
ユーザー sasa
提出日時 2025-03-14 14:04:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 485 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 27,904 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-14 14:04:31
合計ジャッジ時間 1,625 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d",&val);
      |         ~~~~~^~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&pine[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	// 入力された松の数の値
	int val = 0;
	scanf("%d",&val);
	// 各々の松の高さの値
	int pine[val];
	for(int i = 0;i < val;i ++){
		scanf("%d",&pine[i]);
	}
	// 門松列の数
	int count = 0;
	for(int i = 0;i < val - 2;i ++){
		if( (pine[i] != pine[i + 2] && pine[i + 1] > pine[i + 2] && pine[i + 1] > pine[i]) || (pine[i] != pine[i + 2] && pine[i + 1] < pine[i + 2] && pine[i + 1] < pine[i])){
			count++;
		}
	}
	printf("%d",count);
}
0