Import Java.util.arrays;import Java.util.scanner;public class Intarrsot {public static void main (string[] args) {Scanner Scan = new Scanner (system.in); String str = scan.nextline (); String start = str.substring (0, 1); int num = Integer.parseint (start); String end = Str.substring (Str.length ()-1); int check = Integer.parseint (end); String stra = str.substring (2, Str.length ()-1); String []strarr = new String[num];strarr = Stra.split (""); int []intarr = new Int[num];for (int i = 0; i < intarr.length; i++) {Intarr[i] = Integer.parseint (Strarr[i]);} Arrays.sort (Intarr), if (check = = 0) {for (int i = 0; i < intarr.length-1; i++) {System.out.print (Intarr[i] + "");} System.out.println (Intarr[intarr.length-1]);} else if (check = = 1) {for (int j = intarr.length-1; j > 0; j--) {System.out.print (Intarr[j] + "");} System.out.println (Intarr[0]);}}
Compile on Eclipse no problem, do not know why Huawei OJ The result is wrong, 0 points. Ask the great God for advice.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Enter an integer array and sort ID to sort its elements in ascending or descending order