HDU 2020 Absolute Order (Java)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.