Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.3 kB
6
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

#define vi vector<int>

vector<int> rf() {

    vector<int> ans;

    std::ifstream file("pi.txt");
    std::string str; 
    while (std::getline(file, str))
    {
        ans.push_back(str[0] - '0');
    }

    return ans;

}

pair<int, int> solve(vi& a, int x, int y) {

    bool ok = true;
    bool peak = false;
    for (int i = x; i < y; i++) {
        if (y - x > 3 && i < y-1 && (a[i] == a[i+1]) && !peak) {
            return {-1, -1};
        }

        if (a[i] > a[i+1]) {
            peak = true;
            if (i == x) return {-1, -1};
        }
        if ((a[i] <= a[i+1]) && peak) {
            ok = false;
            break;
        }
    }

    if (!ok) return {-1, -1};

    return {x, y};
}

int main() {

    auto v = rf();

    int x = 0,  y= 0;
    for (int i = 0; i < v.size(); i++) {
        for (int j = i; j < v.size(); j++) {

            auto s = solve(v, i, j);
            if (s != pair<int, int>{-1, -1}) {
                if (s.second - s.first > y - x) {
                    x = s.first;
                    y = s.second;
                }
            }
        }  
    }

    cout << x+1 << "\n";
    for (int i = x; i < y+1; i++) {
        cout << v[i] << " ";
    }
    cout << "\n";
}
Leave a Comment