解题思路:
直接结构体排序,一个是源数据,一个是绝对值数据.
参考代码:
#include<bits/stdc++.h> using namespace std; struct num { int pre; int ter; }a[101]; bool comp(num& x, num& y) { return x.ter > y.ter; } int main() { int n; while (cin >> n && n != 0) { for (int i = 0; i < n; i++) { cin >> a[i].pre; a[i].ter = abs(a[i].pre); } sort(a, a + n, comp); for (int i = 0; i < n; i++) { cout << a[i].pre; if (i != n - 1) cout << " "; else cout << endl; } } }
0.0分
3 人评分
C语言训练-计算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m) (C语言代码)浏览:911 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:900 |
校门外的树 (C语言代码)浏览:1123 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:584 |
C语言训练-求素数问题 (C语言代码)浏览:1458 |
C语言训练-求素数问题 (C语言代码)浏览:728 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:770 |
【蟠桃记】 (C语言代码)浏览:664 |
简单的for循环浏览:1410 |