fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <climits>
  5. using namespace std;
  6.  
  7. int main() {
  8. int n;
  9. cin >> n;
  10. vector<long long>v;
  11. for (int i = 0; i < n; i++) {
  12. long long card;
  13. cin >> card;
  14. v.push_back(card);
  15. }
  16. sort(v.begin(), v.end(), less<long long>());
  17.  
  18. long long cnt = 0;
  19. long long maxcnt = 0;
  20. long long maxnum = LLONG_MIN;
  21. for (int i = 1; i < n; i++) {
  22. //다음수로 넘어가면 업데이트
  23. cnt++;
  24. if (v[i - 1] != v[i]) {
  25. //max cnt와 비교
  26. if (maxcnt < cnt) {
  27. maxcnt = cnt;
  28. maxnum = v[i-1];
  29. cnt = 0;
  30. }
  31. }
  32. }
  33.  
  34. cout << maxnum;
  35. return 0;
  36. }
Success #stdin #stdout 0s 4564KB
stdin
6
1
2
1
2
1
2
stdout
1