2 条题解
-
0
#include<stdio.h>
#include
using namespace std;
int a[10005];
void swap(int *p, int *q){
int buf;
buf = *p; *p = *q; *q = buf; return;
}
int find_mode_number(int *arr,int len)
{
int many = 1,less = 1;
int value = 0;
for(int i = 0; i < len; i++)
{
for(int j = i; j < len; j++)
{
if(arr[j] == arr[j+1])
{
less++;
}
else
{
if(many < less)
{
swap(&many,&less);
value = arr[j];
}
less = 1;
break;
}
}
}
return value;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int sum=0;
for(int i=0; i<n; i++)
{
sum+=a[i];
}
double avg=sum1.0/n1.0;
double mid_num;
if(n%2==0)
{
mid_num=(a[(n-1)/2]+a[n/2])*1.0/2.0; }
else
{ mid_num=a[n/2]; } int count=find_mode_number(a,sizeof(a)/sizeof(int)); printf("%.2lf %d %.1lf\n",avg,count,mid_num); return 0;
}
信息
- ID
- 179
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 9
- 标签
- 递交数
- 11
- 已通过
- 6
- 上传者