fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. void solve(){
  5. ll n;
  6. cin>>n;
  7. ll countarray[10]={0};
  8. for(int i=0;i<n;i++){
  9. string s;
  10. cin>>s;
  11. for(int j=0;j<s.length();j++)
  12. countarray[s[j]-'0']++;
  13. }
  14. bool zero=false;
  15. for(int i=1;i<=9;i++){
  16. ll o=countarray[i];
  17. while(o){
  18. cout<<i;
  19. o--;
  20. if(!zero){
  21. zero=true;
  22. ll z=countarray[0];
  23. while(z){
  24. cout<<0;
  25. z--;
  26. }
  27. }
  28. }
  29. }
  30. cout<<endl;
  31. for(int i=9;i>=0;i--){
  32. ll o=countarray[i];
  33. while(o){
  34. cout<<i;
  35. o--;
  36. }
  37. }
  38. cout<<endl;
  39. }
  40. int main()
  41. {
  42. ll t=1;
  43. cin>>t;
  44. while(t--){
  45. solve();
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 15232KB
stdin
1
5
10 20 33 45 68
stdout
1002334568
8654332100