fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100;
  5. const int MAX_VAL = 100000;
  6. const int TEN = 10;
  7.  
  8. int main() {
  9. int n, v[MAX_LENGTH + 1], freq[MAX_VAL];
  10. cin >> n;
  11.  
  12. for (int i = 1; i <= n; ++i) {
  13. cin >> v[i];
  14. if (v[i] == 0) {
  15. cout << "0";
  16. }
  17. int aux = v[i];
  18. while (aux) {
  19. int x = aux % TEN;
  20. ++freq[x];
  21. aux /= TEN;
  22. }
  23. for (int i = 0; i < 10; ++i) {
  24. // cout << freq[i] <<" ";
  25. }
  26.  
  27.  
  28. int flag = 1;
  29. for (int i = 1; i < 10; ++i) {
  30.  
  31. while (freq[i]) {
  32. if (flag == 1 && freq[i] > 0) {
  33. cout << i;
  34. --freq[i];
  35. }
  36. if (freq[0] > 0) {
  37. cout << 0;
  38. --freq[0];
  39. flag = 0;
  40. } else {
  41. flag = 1;
  42. }
  43. if (freq[0] == 0) {
  44. // flag = 1;
  45. }
  46. }
  47. //cout << freq[i] <<" ";
  48. }
  49. for (int i = 0; i < 10; ++i) {
  50. freq[i] = 0;
  51. }
  52. cout << " ";
  53. }
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5280KB
stdin
2
1000000000 999999999


2
123456789 987654321

2
111111 2222222

2
0 21025410

1
110025

5
110025 75439300 987347 324 1203
2
111111 2222222


5
110025 75439300 987347 324 1203

2
585012502   201045801

stdout
10 999999999