Browse Source

问题 F: 【绝对值排序】

webturing 4 years ago
parent
commit
7f5aa16ba0
1 changed files with 27 additions and 0 deletions
  1. 27 0
      F.java

+ 27 - 0
F.java

@@ -0,0 +1,27 @@
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Scanner;
+
+public class F {
+    public static void main(String[] args) {
+        while (cin.hasNext()) {
+            int n = cin.nextInt();
+            if (n == 0) break;
+            Integer[] a = new Integer[n];
+            for (int i = 0; i < a.length; i++) a[i] = cin.nextInt();
+            Arrays.sort(a, new Comparator<Integer>() {
+                @Override
+                public int compare(Integer o1, Integer o2) {
+                    return Math.abs(o2) - Math.abs(o1);
+                }
+            });
+            for (int i = 0; i < a.length; i++) {
+                if (i > 0) System.out.print(" ");
+                System.out.print(a[i]);
+            }
+            System.out.println();
+        }
+    }
+
+    static Scanner cin = new Scanner(System.in);
+}