Advertisement
hopingsteam

Untitled

May 16th, 2020
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include    <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int AP[10], IDX[10];
  6.  
  7. void processDigit(int nr) {
  8.     while(nr)
  9.     {
  10.         int c = nr % 10;
  11.         nr = nr / 10;
  12.         AP[c]++;
  13.     }
  14. }
  15.  
  16. void sortArrays() {
  17.     for(int i = 0; i < 10; i++) {
  18.         for(int j = i + 1; j < 10; j++) {
  19.             if(AP[i] > AP[j]) {
  20.                 swap(AP[i], AP[j]);
  21.                 swap(IDX[i], IDX[j]);
  22.             } else if(AP[i] == AP[j] && IDX[i] > IDX[j]) {
  23.                 swap(IDX[i], IDX[j]);
  24.             }
  25.         }
  26.     }
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32.     for(int i = 0; i < 10; i++)
  33.         IDX[i] = i;
  34.  
  35.     int n;
  36.     cin >> n;
  37.  
  38.     for(int i = 0; i < n; i++)
  39.     {
  40.         int x;
  41.         cin >> x;
  42.         processDigit(x);
  43.     }
  44.  
  45.     sortArrays();
  46.  
  47.     for(int i = 0; i < 10; i++)
  48.     {
  49.         if(AP[i])
  50.             cout << IDX[i] << " ";
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement