码迷,mamicode.com
首页 > 编程语言 > 详细

HDOJ 2020 绝对值排序

时间:2019-03-23 22:24:34      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:back   space   cto   i++   div   names   pre   name   ack   

#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 绝对值排序

标签:back   space   cto   i++   div   names   pre   name   ack   

原文地址:https://www.cnblogs.com/Mered1th/p/10585878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!