解题思路:
冒泡排序
注意事项:
参考代码:
import java.util.Scanner; public class C1169 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); if(n == 0) break; int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = sc.nextInt(); F(a); for(int i = 0; i < n-1; i++) System.out.printf("%d ", a[i]); System.out.printf("%d\n", a[n-1]); } sc.close(); } //冒泡排序 private static void F(int[] a){ int len = a.length, temp = 0; for(int i = 1; i <= len-1; i++){ for(int j = 0; j < len - i; j++){ if(Math.abs(a[j]) < Math.abs(a[j+1])){ temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } } }
0.0分
3 人评分
2005年春浙江省计算机等级考试二级C 编程题(3),复杂度最低的方法没有之一!!!!!浏览:817 |
川哥的吩咐 (C语言代码)浏览:875 |
简单的a+b (C语言代码)浏览:652 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:732 |
【明明的随机数】 (C++代码)浏览:781 |
【亲和数】 (C语言代码)浏览:495 |
ASCII帮了大忙浏览:749 |
拆分位数 (C语言代码)浏览:1327 |
不会做的浏览:874 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:751 |