题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include <iostream> using namespace std; int main() { int n; while(cin>>n){ int arr[n]; for(int i =0;i<n;i++) cin>>arr[i]; for(int i =0;i<n;i++){ if(i==0){ if(arr[0]!=arr[1])cout<<0<<" "; }else if(i==n-1){ if(arr[i]!=arr[n-2])cout<<i<<" "; }else{ if((arr[i]<arr[i+1]&& arr[i]<arr[i-1])||(arr[i]>arr[i+1]&& arr[i]>arr[i-1])) cout<<i<<" "; } }cout<<endl; } } // 64 位输出请用 printf("%lld")