Blue Bridge algorithm implemented in Java Cup training sites from

Questions attractions on training algorithm

Resource constraints
Time limit: 1.0s memory limit: 256.0MB
Problem Description
  Xiao Ming came to a play area, but his time is limited, can not take a stroll to all the attractions, so he downloaded from the Internet each attraction's score, he hopes to the sum of the highest scores of places to visit, so he wants you to help him for N attractions arranged for the sequence.
Input format
  of the first line of input contains a positive integer N, the N spots.
  The second row with N a positive integer representing scores of each attraction.
Output format
  output line, comprising a positive integer N, N indicates the arrangement in descending score attractions in the
sample input
. 4
. 3. 1 2. 4
sample output
4321
data size and conventions
  N <= 1000, each attraction the score <= 10000.



import java.util.Arrays;
import java.util.Scanner;

public class 景点游览 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int [] num = new int[n];
        for (int i=0;i<num.length;i++){
            num[i]=sc.nextInt();
        }
        Arrays.sort(num);
        for (int i=num.length-1;i>=0;i--){
            System.out.printf(num[i]+" ");
        }
    }
}

Released 1085 original articles · won praise 1543 · views 90000 +

Guess you like

Origin blog.csdn.net/a1439775520/article/details/104215834