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.  
  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 areEqual = 1;
  30. for (int i = 1; i <= n; ++i) {
  31. if (v[i] != v[i + 1] && i < n) {
  32. //cout << v[i] <<"<- " <<i << "\n";
  33. areEqual = 0;
  34. }
  35. }
  36.  
  37.  
  38. int index = 0;
  39. if (areEqual == 1) {
  40. cout << "NU AVEM!";
  41. } else {
  42. for (int i = 1; i <= n; ++i) {
  43. int copyVal = v[i];
  44. int freqColor[MAX_LENGTH] = {0};
  45. while (copyVal) {
  46. ++freqColor[copyVal % TEN];
  47. copyVal /= TEN;
  48. }
  49. int flag = 1;
  50. // cout << freqColor[freqDig] <<" ";
  51. for (int i = 0; i < TEN; ++i) {
  52. if (freqColor[freqDig] <= freqColor[i] && freqColor[i] != 0) {
  53. flag = 0;
  54. ++index;
  55. }
  56. }
  57. if (flag == 1) {
  58. cout << v[i] <<" ";
  59. }
  60. }
  61. }
  62. if (index > 0) {
  63. cout << "NU AVEM!";
  64. }
  65.  
  66. // cout << freqDig <<" " << areEqual;
  67.  
  68.  
  69. // cout << "\n"<< freqDig;
  70. return 0;
  71. }
Success #stdin #stdout 0s 5316KB
stdin
3
1122 1212 2211
stdout
NU AVEM!