题意:对于输入的数字,拼接成一个最大的数字
解法:把数字当成字符串处理,排序,输出即可
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); int n; while ((n = in.nextInt()) != 0) { String[] list = new String[n]; int i = 0; while (n != 0) { list[i++] = in.next(); n--; } Arrays.sort(list,new Cmp()); for (i = list.length - 1; i >= 0; i--) System.out.print(list[i]); System.out.println(); } } static class Cmp implements Comparator<String> { @Override public int compare(String o1, String o2) { String str1 = o1+o2; String str2 = o2+o1; return str1.compareTo(str2); } } }