HDOJ 2020 绝对值排序

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

using namespace std;
bool cmp(int a, int b) {
    return abs(a) > abs(b);
}

int main() {
    int n;
    while (cin >> n && n != 0) {
        vector<int> v;
        int t;
        for (int i = 0;i < n;i++) {
            cin >> t;
            v.push_back(t);
        }
        sort(v.begin(), v.end(), cmp);
        for (auto it = v.begin();it != v.end();it++) {
            if (it == v.begin()) cout << *it;
            else cout << " " << *it;
        }
        cout << endl;
    }

    return 0;
}

猜你喜欢

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