fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 20;
  5. const int TEN = 10;
  6. int freq[TEN + 1];
  7.  
  8. int main() {
  9. int n, v[MAX_LENGTH + 1];
  10. cin >> n;
  11. for (int i = 1; i <= n; ++i) {
  12. cin >> v[i];
  13. int copyEl = v[i];
  14. while (copyEl) {
  15. ++freq[copyEl % TEN];
  16. copyEl /= TEN;
  17. }
  18. }
  19. int indexFreqDig = 0, aux = 0;
  20. for (int i = 0; i <= TEN; ++i) {
  21. if (aux < freq[i]){
  22. aux = freq[i];
  23. indexFreqDig = i;
  24. }
  25. //cout << freq[i] <<" ";
  26. }
  27. //cout << aux << " de cate ori apare " << indexFreqDig << "\n";
  28. // cout << indexFreqDig << " cifra frecventa \n";
  29. int flag = 0;
  30. for (int i = 0; i <= TEN ; ++i) {
  31. // cout << freq[i] <<" <-> ";
  32. if (aux == freq[i] ) {
  33. flag = 1;
  34. } else if (aux == freq[i] ) {
  35.  
  36. }
  37. // cout << flag << "\n";
  38. }
  39. // cout << "\n" << flag <<" <-\n";
  40. for (int i = 1; i <= n; ++i) {
  41. for (int i = 0; i <= TEN; ++i) {
  42. freq[i] = 0;
  43. }
  44. int copyEl = v[i];
  45. while (copyEl) {
  46. ++freq[copyEl % TEN];
  47. copyEl /= TEN;
  48. }
  49. int aparitie = 0, index = 0;
  50. for (int i = 0; i <= TEN; ++i) {
  51.  
  52. if (aparitie < freq[i]) {
  53. aparitie = freq[i];
  54. index = i;
  55. }
  56. }
  57. // cout << "index -> "<< index << " cu numarul de aparitii " << aparitie << "\n";
  58. if (index == indexFreqDig && flag == 1) {
  59. cout << v[i] <<" ";
  60. } ///else {
  61. // cout << "NU AVEM!";
  62. //break;
  63. //}
  64. }
  65.  
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5316KB
stdin
3
123 123 123
3
122 111 1231

3
123 123 123
7
2222 4123 111 221 5261 9994 51212


3
123 123 123

7
2222 4123 111 221 5261 9994 51212

3
122 111 1231

3
722 711 7237
stdout
123 123 123