Problem:
Note the input method, which can be loaded directly with an array.
Absolute OrderTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 51480 Accepted Submission (s): 24867
Problem description Input n (n<=100) integers, sorted by absolute value from large to small. The title guarantees that for each test instance, the absolute value of all the numbers is not equal.
Input data has more than one group, each group is a row, the first number of each row is n, followed by n integers, n=0 represents the end of the input data, do not do processing.
Output for each test instance, outputs the sorted results, separated by a space between two numbers. Each test instance occupies one row.
Sample Input
3 3-4 24 0 1 2-30
Sample Output
-4 3 2-3 2 1 0
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); int N;int [] a=new Int[100];while (Cin.hasnext ()) {n=cin.nextint (); if (n==0) break;//int a[]=new int[100];for (int i=0;i<n;i++) A[i]=cin.nextint (); for (int i=0;i<n-1;i++) {for (int j=i+1;j<n;j++) {if (Math.Abs (A[i]) <math.abs (A[j])) {int X =a[j];a[j]=a[i];a[i]=x;}}} for (int i=0;i<n;i++) {if (i==0) System.out.print (A[i]); ElseSystem.out.print ("" +a[i]);} System.out.println ();}}}
HDU 2020 Absolute Order (Java)