题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include<iostream> using namespace std; const int N = 100; int main(void) { int arr[N]; int n; while(cin >> n) { for(int i = 0;i < n;i++) cin >> arr[i]; for(int i = 0;i < n;i++) { if(i == 0 && arr[i + 1] != arr[i]) cout << i << " "; if(i == n - 1 && arr[i] != arr[i - 1]) cout << i << " "; if(i > 0 && i < n - 1) { if(arr[i] < arr[i - 1] && arr[i] < arr[i + 1]){ cout << i << " "; } if(arr[i] > arr[i - 1] && arr[i] > arr[i + 1]){ cout << i << " "; } } } puts(""); } return 0; }