csp认证 201509-1 数列分段

遍历输入数据,存在前后不相等的情况就记录。

//
// Created by 29273 on 2021-04-02.
//
#include "bits/stdc++.h"

using namespace std;
int a[1001];
int res = 1;

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