import java.util.Scanner;
public class P1012拼数 {
// 局部最优解
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String[] ss = new String[n];
ss = sc.nextLine().split(" ");
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
String s1 = ss[i] + ss[j];
String s2 = ss[j] + ss[i];
if (s1.compareTo(s2) < 0) {
String temp = ss[i];
ss[i] = ss[j];
ss[j] = temp;
}
}
}
for (int i = 0; i < n; i++)
System.out.print(ss[i]);
sc.close();
}
}
[java]P1012拼数题解 全AC 代码简洁
最新推荐文章于 2024-11-01 14:48:20 发布