fork(1) 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. ++freq[aux % TEN];
  20. aux /= TEN;
  21. }
  22.  
  23. int flag = 1;
  24. for (int i = 1; i < 10; ++i) {
  25.  
  26. while (freq[i]) {
  27. if (flag == 1 && freq[i] > 0) {
  28. cout << i;
  29. --freq[i];
  30. }
  31. if (freq[0] > 0) {
  32. cout << 0;
  33. --freq[0];
  34. flag = 0;
  35. } else {
  36. flag = 1;
  37. }
  38. if (freq[0] == 0) {
  39. // flag = 1;
  40. }
  41. }
  42. //cout << freq[i] <<" ";
  43. }
  44. for (int i = 0; i < 10; ++i) {
  45. freq[i] = 0;
  46. }
  47. cout << " ";
  48. }
  49.  
  50. return 0;
  51. }
Success #stdin #stdout 0s 5324KB
stdin
2
0 21025410

1
110025

5
110025 75439300 987347 324 1203



5
110025 75439300 987347 324 1203

2
585012502   201045801

stdout
0 10012245