Sdut 1196-Sorting problems (Java class sort)

Source: Internet
Author: User

Sorting issues Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ The title description enters 10 integers, outputs them from small to large, and gives the position of each element in the original sequence. Input input data has a row, containing 10 integers, separated by a space. The output output data has two lines, the first behavior is sorted after the sequence, and the second behaves after the position of each element in the original sequence. Sample input
1 2 3 5 4 6 8 9 10 7
Sample output
1 2 3 4 5 6 7 8 9 101 2 3 5 4 6 10 7 8 9
The sort provided by the arrays class can only be sorted in ascending order, and is a monotone number or letter, but can be modified by the comparator comparer to sort the class, I thought about it. Perhaps this enables a descending sort of a single numeric array? Let's try.
Import java.io.*;import java.util.*;import java.math.*;import java.text.*;class node{public  int tag,num;} Class CMP implements Comparator<node>{public int Compare (node A,node B) {return a.num-b.num;}}  public class Main {public static void main (string[] args) {Scanner in=new Scanner (system.in); node[] a=new node[11];for (int i=0;i<10;i++) {a[i]=new node (); A[i].num=in.nextint (); a[i].tag=i+1;} Arrays.sort (a,0,10,new cmp ()); for (int i=0;i<10;i++) if (i!=9) System.out.print (a[i].num+ ""); elseSystem.out.print (A[i].num); System.out.println (""); for (int i=0;i<10;i++) if (i!=9) System.out.print (a[i].tag+ ""); ElseSystem.out.print (A[i]. TAG); System.out.println ("");}}

Sdut 1196-Sorting problems (Java class sort)

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.