0
Help us understand the problem. What are the problem?

posted at

updated at

Atcoder 解答例 AGC 013 A - Sorted Arrays

AGC 013 A - Sorted Arrays 解答例

問題はこちら

解答例が見当たらなかったため、備忘録がてら投稿します。
何かアドバイスがあれば気軽にコメントください。

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    int N;
    cin >> N;

    int A[100001];
    int split_count = 0;

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    bool is_up = false;
    bool is_down = false;

    for (int i = 0; i < N-1; i++) {
        if (A[i] - A[i + 1] < 0) {
            is_up = true;
        }
        else if (A[i] - A[i + 1] > 0) {
            is_down = true;
        }

        if (is_up == true && is_down == true) {
            split_count++;
            is_up = false;
            is_down = false;
        }
    }

    cout << split_count + 1 << endl;

    return 0;
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?