-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDay0.cpp
78 lines (73 loc) · 1.41 KB
/
Day0.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
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
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll mod = 1000000007;
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
int countFreq(int arr[], int n)
{
map<int, int> mp;
int result;
for (int i = 0; i < n; i++)
mp[arr[i]]++;
int max = 0;
for (auto x : mp)
{
if (x.second > max)
{
max = x.second;
result = x.first;
}
}
return result;
}
int main()
{
cin.sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int arr[n];
int sum = 0;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
}
// for (int i = 0; i < n; i++)
// {
// cout<< arr[i]<<" ";
// // sum += arr[i];
// }
sort(arr, arr + n);
double mean = (double)sum / n;
int mode = countFreq(arr, n);
double median;
if (n % 2 == 0)
{
median = ((double)arr[(n / 2)] + (double)arr[(n / 2) - 1]) / 2.0;
}
else
{
median = arr[(int)(n / 2)];
}
printf("%.1f\n",mean);
printf("%.1f\n",median);
printf("%d\n",mode);
return 0;
}