fork(1) 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.  
  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, areEqual = 1;
  14. for (int i = 1; i <= n; ++i) {
  15. cin >> v[i];
  16. if (v[i] < 0) {
  17. v[i] = -v[i];
  18. }
  19. if (i > 1 && v[i] != v[i- 1]) {
  20. //cout << v[i] <<"<- " <<i << "\n";
  21. areEqual = 0;
  22. }
  23. int copyEl = v[i];
  24. while (copyEl) {
  25. ++freq[copyEl % TEN];
  26. if (freq[copyEl % TEN] > aparitii) {
  27. aparitii = freq[copyEl % TEN];
  28. freqDig = copyEl % TEN;
  29. }
  30. copyEl /= TEN;
  31. }
  32. }
  33. //cout << areEqual <<" " << freqDig <<" <- \n";
  34. //,
  35. for (int i = 1; i <= n; ++i) {
  36. //
  37.  
  38. }
  39. //if (v[i] >= bigNo && v[i] != 0) {
  40. // bigNo = v[i];
  41. // }
  42.  
  43. int index = 0;
  44. if (areEqual == 1) {
  45. //cout << "NU AVEM!";
  46. } //else {
  47. for (int i = 1; i <= n; ++i) {
  48. int copyVal = v[i];
  49. int freqColor[MAX_LENGTH] = {0};
  50. while (copyVal) {
  51. ++freqColor[copyVal % TEN];
  52. copyVal /= TEN;
  53. }
  54. int flag = 1;
  55. // cout << freqColor[freqDig] <<" ";
  56. int aux = 0, bigNo = 0;
  57. for (int i = 0; i < TEN; ++i) {
  58. if (freqColor[i] >= aux && freqColor[i] != 0) {
  59. //cout << freqColor[i] <<" " << i << " \n";
  60. aux = freqColor[i];
  61. bigNo = i;
  62. }
  63.  
  64. //if (freqColor[freqDig] <= freqColor[i] && freqColor[i] != 0) {
  65. // flag = 0;
  66. // ++index;
  67. //}
  68. }
  69. //cout << bigNo <<"<- ";
  70. if (bigNo == freqDig) {
  71. cout << v[i] <<" ";
  72. ++index;
  73. }
  74. }
  75. // }
  76. if (index == 0 || areEqual == 1) {
  77. cout << "NU AVEM!";
  78. }
  79.  
  80. // cout << freqDig <<" " << areEqual;
  81.  
  82.  
  83. // cout << "\n"<< freqDig;
  84. return 0;
  85. }
Success #stdin #stdout 0.01s 5288KB
stdin
3
122 111 1231
stdout
111 1231