Advertisement
Spocoman

04. Most Frequent Number

Oct 27th, 2023 (edited)
709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int length, number, maxFrequency = 0;
  7.     cin >> length;
  8.  
  9.     int frequencies[10] = { 0 };
  10.  
  11.     for (int i = 0; i < length; i++) {
  12.         cin >> number;
  13.         frequencies[number]++;
  14.     }
  15.  
  16.     for (int i = 0; i < 10; i++)
  17.     {
  18.         if (maxFrequency < frequencies[i]) {
  19.             maxFrequency = frequencies[i];
  20.         }
  21.     }
  22.  
  23.     for (int i = 0; i < 10; i++) {
  24.         if (maxFrequency == frequencies[i]) {
  25.             cout << i << ' ';
  26.         }
  27.     }
  28.     cout << endl;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement