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