//小傻瓜呀,這麼簡單都能想麻煩
#include<iostream> using namespace std; int main(){ int n; cin>>n; int* a=new int[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int cou=0; for(int i=1;i<n-1;i++){ int b=a[i]-a[i-1]; int c=a[i]-a[i+1]; if(b*c>0) cou++; } cout<<cou<<endl; delete[] a; return 0; }
#include <cstdio> int main() { int N; scanf("%d", &N); if(N < 3) { printf("%d", 0); return 0; } int cnt = 0; int pre, cur, next; scanf("%d", &pre); scanf("%d", &cur); for(int n=2; n<N; n++) { scanf("%d", &next); if(cur > pre && cur > next) cnt++; else if(cur < pre && cur < next) cnt++; pre = cur; cur = next; } printf("%d", cnt); }
//http://www.javashuo.com/article/p-szwtpxvt-kr.html