//BAEKJOON 2108
#include <stdio.h>
int main()
{
int N, n=0, min=4000, max=-4000, F0=0, F=0, m=0; //n:지금까지 나온 숫자 개수, m:중앙값
int s[500001]= {}, S[8002]= {}, f[8002]= {}; //S:개수, f:빈도
double sm=0;
scanf("%d", &N);
for(int i=0; i<N; i++)
{
scanf("%d", &s[i]);
S[s[i]+4000]++;
}
for(int i=0; i<N; i++)
{
sm+=s[i];
if(max<s[i])
max=s[i];
if(min>s[i])
min=s[i];
}
for(int i=0; i<8001; i++)
{
if(n<=N/2&&n+S[i]>=N/2+1)
m=i-4000;
n+=S[i];
if(S[F0]<S[i]) //F0 : 최빈값
{
F0=i;//최빈값
for(int i=0; i<8001; i++)
f[i]=0;
f[0]=i-4000;
F=1; //최빈값 개수
}
else if(S[F0]==S[i])
{
f[F]=i-4000;
F++;
}
}
if(f[1]!=0)
{
if(sm<0)
printf("%d\n%d\n%d\n%d", (int)((sm/N)-0.5), m, f[1], max-min);
else
printf("%d\n%d\n%d\n%d", (int)((sm/N)+0.5), m, f[1], max-min);
}
else
{
if(sm<0)
printf("%d\n%d\n%d\n%d", (int)((sm/N)-0.5), m, f[0], max-min);
else
printf("%d\n%d\n%d\n%d", (int)((sm/N)+0.5), m, f[0], max-min);
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: