1. 程式人生 > >HDOJ 2020 絕對值排序

HDOJ 2020 絕對值排序

() nbsp class begin back math clu hdoj auto

#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; }

HDOJ 2020 絕對值排序