fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. int n;
  11. cin>>n;
  12. string a[n];
  13. for(int i=0;i<n;i++)
  14. {
  15. cin>>a[i];
  16. }
  17. int counter[10];
  18. for(int i=0;i<10;i++) counter[i] = 0;
  19.  
  20. for(int i=0;i<n;i++)
  21. {
  22. for(int j=0;j<a[i].length();j++)
  23. counter[a[i][j]-48]++;
  24. }
  25.  
  26. bool zeroDone = false;
  27. bool nonZeroStarted = false;
  28. for(int i=1;i<=9;i++)
  29. {
  30. int x= counter[i];
  31. while(x--)
  32. {
  33. nonZeroStarted = true;
  34. cout<<i;
  35. if(nonZeroStarted && !zeroDone)
  36. {
  37. zeroDone = true;
  38. int x= counter[0];
  39. while(x--)
  40. {
  41. cout<<0;
  42. }
  43. }
  44. }
  45. }
  46. cout<<endl;
  47. for(int i=9;i>=0;--i)
  48. {
  49. int x=counter[i];
  50. while(x)
  51. {
  52. cout<<i;
  53. x--;
  54. }
  55. }
  56. cout<<endl;
  57. }
  58. }
Success #stdin #stdout 0s 16056KB
stdin
1
5
10 20 33 45 68
stdout
1002334568
8654332100