fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Solution
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Scanner sc = new Scanner(System.in);
  13. int t = sc.nextInt();
  14.  
  15. while(t-- > 0){
  16. int n = sc.nextInt();
  17. String[] arr = new String[n];
  18.  
  19. for(int i = 0; i < n; i++){
  20. arr[i] = String.valueOf(sc.nextInt());
  21. }
  22.  
  23. ArrayList<String> solutionList = new ArrayList<>(Arrays.asList(arr));
  24.  
  25. Collections.sort(solutionList, (x, y) -> (y + x).compareTo(x + y));
  26.  
  27. for(int i = 0; i < n; i++){
  28. System.out.print(solutionList.get(i));
  29. }
  30.  
  31. System.out.println();
  32. }
  33. }
  34. }
Success #stdin #stdout 0.16s 56100KB
stdin
3
8
49 73 58 30 72 44 78 23 
4
69 9 57 60 
2
40 4 
stdout
7873725849443023
9696057
440