๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11652๋ฒˆ - ์นด๋“œ

by dkswnkk 2021. 10. 31.
 

11652๋ฒˆ: ์นด๋“œ

์ค€๊ทœ๋Š” ์ˆซ์ž ์นด๋“œ N์žฅ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ˆซ์ž ์นด๋“œ์—๋Š” ์ •์ˆ˜๊ฐ€ ํ•˜๋‚˜ ์ ํ˜€์žˆ๋Š”๋ฐ, ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -262๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 262๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ์ค€๊ทœ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์นด๋“œ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ๊ฐ€์žฅ ๋งŽ์ด ๊ฐ€์ง€

www.acmicpc.net

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N; 
    cin >> N;
    vector<long long> number;
    int cnt = 1, max = 1;
    long long ans;

    for (int i = 0; i < N; i++) {
        long long num;
        cin >> num;
        number.push_back(num);
    }
    sort(number.begin(),number.end());
    ans = number[0];
    for (int i = 1; i < N; i++) {
        if (number[i] == number[i-1]) {
            cnt++;
            if (max < cnt) {
                max = cnt;
                ans = number[i];
            }
        }
        else cnt = 1;
    }
    cout << ans;

}

๋Œ“๊ธ€