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