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. 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. if (copyVal % TEN == freqDig) {
  34. ++color;
  35. }
  36. copyVal /= TEN;
  37. //++freqColor[copyEl % TEN];
  38. }
  39. freq[++index] = color;
  40. //cout << color <<" ";
  41. }
  42.  
  43.  
  44. for (int i = 1; i <= index; ++i) {
  45. cout << freq[i] <<" ";
  46. }
  47. cout << "\n"<< freqDig;
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5308KB
stdin
3
122 111 1231
stdout
1 3 2 
1