acm 2020 Java 绝对值排序
1 import java.util.Scanner; 2 3 /** 4 * Created by Administrator on 2016/4/4. 5 */ 6 7 class EMP { 8 9 int emp[]; 10 11 public EMP (int temp[]){ 12 emp = temp; 13 } 14 15 public int[] sort() { 16 for (int i = 0; i < emp.length - 1; i++) { 17 for (int j = 0; j < emp.length - 1 - i; j++) { 18 19 if ((Math.abs(emp[j])) <(Math.abs(emp[j + 1])) ) { 20 int b; 21 b = emp[j]; 22 emp[j] = emp[j + 1]; 23 emp[j + 1] = b; 24 25 } 26 } 27 } 28 // ... 29 return emp; 30 } 31 } 32 33 public class Main { 34 public static void main(String []args) { 35 Scanner in = new Scanner(System.in); 36 for (; ; ) { 37 int c = in.nextInt(); 38 if (c == 0) { 39 System.exit(0); 40 41 } 42 int[] a = new int[c]; 43 for (int k = 0; k < a.length; k++) { 44 a[k] = in.nextInt(); 45 } 46 EMP b = new EMP(a); 47 48 a = b.sort(); 49 for (int i = 0; i < a.length - 1; i++) { 50 System.out.print(a[i] + " "); 51 } 52 System.out.println(a[c - 1]); 53 54 } 55 } 56 }
Code