题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include<cstdio> int main(){ int n; int arr[100]; while(scanf("%d",&n) != EOF){ for(int i = 0 ; i < n ; ++ i){ scanf("%d",&arr[i]); } if(arr[0] != arr[1]){ printf("%d ",0); } for(int i = 1; i < n-1 ; ++ i){ if(arr[i]> arr[i+1] && arr[i]> arr[i-1] || arr[i]< arr[i+1] && arr[i]< arr[i-1]){ printf("%d ",i); } } if(arr[n] != arr[n-1]){ printf("%d",n-1); } } }