Advertisement
vafin20

Untitled

Jun 11th, 2020
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int count[16];
  6.     int names[16];
  7.     for(int i = 0; i < n; ++i) {
  8.         count[i] = 0;
  9.         names[i] = i;
  10.     }
  11.     for(int i = 0; i < n; ++i) {
  12.         names[i] = i;
  13.     }
  14.     int n;
  15.     cin >> n;
  16.     int x;
  17.     for(int i = 0; i < n; ++i) {
  18.         cin >> x;
  19.         ++count[x - 1];
  20.     }
  21.     for(int i = 0; i < 15; ++i) {
  22.         for(int j = i + 1; j < 16; ++j) {
  23.             if(count[j] > count[i]) {
  24.                 swap(count[i], count[j]);
  25.                 swap(names[i], names[j]);
  26.             }
  27.         }
  28.     }
  29.  
  30.     for(int i = 0; i < 16; ++i) {
  31.         if(count > 0) {
  32.             cout << names[i] << " " << count[i] << endl;
  33.         }
  34.     }
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement