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

3
122 111 1231

stdout
123 123 123