Here is the code in C++:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void SORT(vector<int>& x, vector<int>& y, vector<int>& s) {
    int n = s.size();
    int m = x.size();

    for (int i = 0; i < m; i++) {
        if (x[i] > y[i]) {
            swap(x[i], y[i]);
        }
    }

    for (int i = 0; i < m; i++) {
        for (int j = x[i]; j < y[i]; j++) {
            if (s[j] > s[j+1]) {
                swap(s[j], s[j+1]);
            }
        }
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> s(n);

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

    int m;
    cin >> m;
    vector<int> x(m), y(m);

    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
    }

    SORT(x, y, s);

    for (int i = 0; i < n; i++) {
        cout << s[i] << " ";
    }
    cout << endl;

    return 0;
}

Note that the code assumes that the input is valid, i.e., the length of the sequence s is n and the lengths of x and y are both m. It also assumes that the elements of s are either 0 or 1

Given a 01-sequence sequence consisting only of 0s and 1s sss of length nnn you need to find two arrays xxx and yyy such that Array xxx and yyy are of equal length and the length should not exceed 120

原文地址: https://www.cveoy.top/t/topic/h7Py 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录