-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2108.cpp
42 lines (39 loc) · 1005 Bytes
/
2108.cpp
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
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
vector<int> arr;
int main() {
int num,tmp,range,middle = 0,most_val,mean = 0;
int most = -9999;
int number[8001] = {0,};
bool not_first = false;
cin >> num;
for(int i = 0; i < num; i++){
cin >> tmp;
arr.push_back(tmp);
mean += tmp;
number[tmp+4000]++;
}
sort(arr.begin(),arr.end());
for(int i = 0; i < 8001; i++){
if(number[i] == 0)
continue;
if(number[i] == most){
if(not_first){
most_val = i - 4000;
not_first = false;
}
}
if(number[i] > most){
most = number[i];
most_val = i - 4000;
not_first = true;
}
}
middle = arr[arr.size()/2];
mean = round((float)mean / num);
range = arr.back() - arr.front();
cout << mean << '\n' << middle << '\n' << most_val << '\n' << range;
}