[BOJ / C++] 2108 통계학

Seulguo·2022년 7월 18일
0

Algorithm

목록 보기
84/185
post-thumbnail
post-custom-banner

🐣 문제

링크 : https://www.acmicpc.net/problem/2108


🐥 코드

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    int n = 0; 
    cin >> n;
    
    vector<int> v;
    int arr[8001] = {0};
    double sum = 0;

    for(int i = 0; i < n; i++){
        int tmp = 0;;
        cin >> tmp;
        v.push_back(tmp);
        sum += tmp;
        arr[tmp + 4000]++;
    }

    if(round(sum/double(n))==-0)
        cout<<'0'<<"\n";
    else
        cout<<round(sum/double(n))<<"\n";
    
    sort(v.begin(), v.end());
    cout << v[n/2] << "\n";

    int idx;
    int max = 0;
    for(int i = 0; i < 8001; i++){
        if(arr[i] > max){
            max = arr[i];
            idx = i;
        }
    }

    for(int i = idx+1; i < 8001; i++){
        if(arr[i] == max){
        idx = i;
        break;
        }
    }
  
    cout << idx-4000 << '\n';

    int m1 = *max_element(v.begin(), v.end());
    int m2 = *min_element(v.begin(), v.end());
 
    cout << m1 - m2 << '\n';
    
    return 0;
}
post-custom-banner

0개의 댓글