简单遍历
打印极值点下标
http://www.nowcoder.com/questionTerminal/7fd72f8ac7964ba3b8baa8735246e1f1
#include <stdio.h> int main(){ int n,i; while(scanf("%d",&n)!=EOF) { int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); if(a[0]!=a[1]) printf("0 "); for(i=1;i<n-1;i++) { if(a[i]>a[i-1]&&a[i]>a[i+1]) printf("%d ",i); else if(a[i]<a[i-1]&&a[i]<a[i+1]) printf("%d ",i); } if(a[n-1]!=a[n-2]) printf("%d",n-1); printf("\n"); } }(•̀ᴗ•́)و