rengetsu

HackerRank_MigratoryBirds

Jul 5th, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. //Migratory Birds
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5.     int n, tmp = -1, ats = -1, mxNum = -1;
  6.     cin >> n; //Number of birds
  7.     vector<int> tip(n);
  8.     for(int tip_i = 0; tip_i < n; tip_i++)
  9.     {
  10.        cin >> tip[tip_i];
  11.        if(tip[tip_i] > mxNum)
  12.        {
  13.            mxNum = tip[tip_i];
  14.        }
  15.     }
  16.     vector<int> cnt(mxNum,0);
  17.     for(int i = 0; i < tip.size(); i++)
  18.     {
  19.         cnt[tip[i]]++;
  20.     }
  21.     for(int i = 0; i <= mxNum; i++)
  22.     {
  23.         if(cnt[i] > tmp){
  24.             tmp = cnt[i];
  25.             ats = i;
  26.         }
  27.     }
  28.     cout << ats << endl;
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment