본문 바로가기

Algorithm

(C++) - 백준(BOJ) 2592 : 대표값

반응형
#include <iostream>
using namespace std;

int main() {
    int average=0, mn, arr[10], cnt = 0, ary[10],big = 0, att[10], index;
    
    for (int i = 0; i < 10; i++)
    {
        cin >> arr[i];
        average += arr[i];
    }
    average /= 10;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            mn = arr[i];
            att[i] = arr[i];
            if (arr[j] == mn)
            {
                cnt++;
                
            }
        }
        ary[i]= cnt;
        cnt = 0;
    }
    for (int i = 0; i < 10; i++)
    {
        if (ary[i] > big)
        {
            big = ary[i];
            index = att[i];
        }
    }
    cout << average << '\n' << index;
}