#include #include using namespace std;

int main() { int a, b, c; cin >> a >> b >> c; int abs_a = abs(a); int abs_b = abs(b); int abs_c = abs(c);

// 定义一个数组保存输入的数字和其对应的绝对值
pair<int, int> nums[3] = {{a, abs_a}, {b, abs_b}, {c, abs_c}};

// 按照绝对值从小到大排序
sort(nums, nums + 3, [](pair<int, int> num1, pair<int, int> num2){
    if(num1.second == num2.second) {
        return num1.first < num2.first;
    } else {
        return num1.second < num2.second;
    }
});

// 输出排序后的结果
for(int i = 0; i < 3; i++) {
    cout << nums[i].first << " ";
}

return 0;
描述输入 3 个整数按绝对值从小到大排序。输入描述输入包含 3 个int范围内的整数用空格隔开。输出描述输出一行包含三个数用空格隔开。若两个数字的绝对值一样则比较两个数字的大小。用例输入 1 1 3 -3用例输出 1 1 -3 3用c++做

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

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