CSP认证201604-1折点计数

遍历判断左右与其满足关系

int judge(int x, int y, int z) {
    return (x < y && x < z) || (x > y && x > z);
}
//
// Created by 29273 on 2021-04-02.
//
#include "bits/stdc++.h"

using namespace std;
int a[1001];

int judge(int x, int y, int z) {
    return (x < y && x < z) || (x > y && x > z);
}

int main() {
    int n, res = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i < n - 1; i++) {
        res += judge(a[i], a[i - 1], a[i + 1]);
    }
    cout << res << endl;
    return 0;
}
posted @ 2021-04-09 15:21  沃特艾文儿  阅读(15)  评论(0)    收藏  举报  来源