HDOJ 2019 数列有序!

#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

bool cmp(int a, int b) {
    return a < b;
}

bool cmp2(int a, int b) {
    return a > b;
}

int main() {
    int n, m;
    while (cin >> n && cin >> m && (n != 0 && m != 0)) {
        vector<int> ans;
        int t;
        while (n--) {
            cin >> t;
            ans.push_back(t);
        }
        ans.push_back(m);
        if (ans[0] > ans[1]) {
            sort(ans.begin(), ans.end(), cmp2);
        }
        else {
            sort(ans.begin(), ans.end(), cmp);
        }
        for (auto it = ans.begin();it != ans.end();it++) {
            if (it == ans.begin()) cout << *it;
            else cout << " " << *it;
        }
        cout << endl;
    }

    return 0;
}

有个坑点,题目中的有序没说是降序还是升序!

猜你喜欢

转载自www.cnblogs.com/Mered1th/p/10585875.html