题解 | #打印极值点下标#

打印极值点下标

https://www.nowcoder.com/practice/7fd72f8ac7964ba3b8baa8735246e1f1

#include <iostream>

using namespace std;

const int MAXN = 80 + 10;
int a[MAXN];

int main () {
	int n;
	while (scanf ("%d", &n) != EOF){
		for (int i = 0; i < n; i++){
			scanf ("%d", &a[i]);
		}
		for (int i = 0; i < n; i++){
			if (i == 0){
				if (a[i + 1] != a[i]){
					cout << i << " ";
				}
			}else if (i == n - 1){
				if (a[i] != a[i - 1]){
					cout << i << " ";
				}
			}else if (a[i] > a[i - 1] && a[i] > a[i + 1] || a[i] < a[i - 1] && a[i] < a[i + 1]){
				cout << i << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

全部评论

相关推荐

鼗:四级有点难绷,感觉能拿国家励志奖学金,学习能力应该蛮强的,四级确实不重要,但是拿这个卡你可是很恶心啊
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务