-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2108.cpp
More file actions
69 lines (62 loc) · 1.22 KB
/
2108.cpp
File metadata and controls
69 lines (62 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#define MAX 500000
using namespace std;
int N;
double sum = 0;
int arr[MAX + 1];
map<int, int> m;
bool compare(pair<int, int>& a, pair<int, int>& b) {
return a.second > b.second;
}
int main() {
cin >> N;
for (int n = 0; n < N; n++) {
cin >> arr[n];
sum += arr[n];
m[arr[n]] = 0;
}
// 산술평균 (소수점 아래 첫째자리에서 반올림)
double avg = round((sum / N));
if (avg == -0) {
cout << 0 << endl;
}
else {
cout << avg << endl;
}
// 중앙값 (N은 홀수)
sort(arr, arr + N);
cout << arr[N / 2] << endl;
// 최빈값 (여러개 일 경우 두번째로 작은 값 출력
if (N == 1) {
cout << arr[0] << endl;
}
else {
for (int n = 0; n < N; n++) {
m[arr[n]]++;
}
//for (auto x : m) { // for check
// cout << x.first << ", " << x.second << endl;
//}
vector<pair<int, int>> v;
for (auto& it : m) {
v.push_back(it);
}
sort(v.begin(), v.end(), compare);
//for (auto& it : v) { // for check
// cout << it.first << ", " << it.second << endl;
//}
if (v[0].second == v[1].second) {
cout << v[1].first << endl;
}
else {
cout << v[0].first << endl;
}
}
// 범위
cout << arr[N - 1] - arr[0] << endl;
return 0;
}