题解 | #打印极值点下标#
打印极值点下标
https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1
#include <stdio.h> int main(){ //输入 int num; while (scanf("%d", &num) != EOF){ int arr[num]; for (int i = 0; i < num; ++i) { scanf("%d", &arr[i]); } //判断并输出,第一个和最后一个数单独判断 if (arr[0] != arr[1]){ printf("0 "); } for (int i = 1; i < num - 1; ++i) { if (arr[i] > arr[i-1] && arr[i] > arr[i+1]){ printf("%d ", i); } else if (arr[i] < arr[i-1] && arr[i] < arr[i+1]){ printf("%d ", i); } } if (arr[num-1] != arr[num-2]){ printf("%d", num-1); } printf("\n"); } return 0; }