fork download
  1. import java.util.*;
  2.  
  3. /*
  4. プログラミングのお題スレ Part12
  5. ttps://mevius.5ch.net/test/read.cgi/tech/1538096947/614
  6.  
  7. 614 名前:デフォルトの名無しさん[sage] 投稿日:2018/11/21(水) 21:03:37.61 ID:Gj+ctZjI
  8. お題
  9. N個の正整数を並べ替えたあと結合してできる整数の最小値を求めよ
  10.  
  11. 3 2 1
  12. => 123
  13.  
  14. 1 2 21
  15. => 1212
  16.  
  17. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
  18. => 10111121314151623456789
  19. */
  20. class Ideone
  21. {
  22. public static void main(String[] args)
  23. {
  24. try (Scanner in = new Scanner(System.in))
  25. {
  26. while(in.hasNextLine())
  27. {
  28. String[] strs = in.nextLine().split(" ");
  29. Arrays.sort(strs, (x, y) -> (x + y).compareTo(y + x));
  30. for (String s : strs) System.out.print(s);
  31. System.out.println();
  32. }
  33. }
  34. }
  35. }
Success #stdin #stdout 0.15s 2184192KB
stdin
3 2 1
1 2 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
10 11 101 100
101 10
10 101
stdout
123
1212
10111121314151623456789
1001010111
10101
10101