Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟

原题连接:http://codeforces.com/contest/580/problem/A

题意:

给你一个序列,问你最长不降子串是多长?

题解:

直接模拟就好了

代码:

#include<iostream>
using namespace std;

int n;

int main() {
    cin.sync_with_stdio(false);
    cin >> n;
    int p;
    cin >> p;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    int maxLen = 1;
    int now = 1;
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        if (a >= p) {
            now++;
            maxLen = max(maxLen, now);
        }
        else {
            maxLen = max(maxLen, now);
            now = 1;
        }
        p = a;
    }
    cout << max(now, maxLen) << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/HarryGuo2012/p/4831098.html