首页 > 其他 > 详细

HDU 2014

时间:2014-12-08 22:55:58      阅读:396      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

typedef float ElementType;
void Select_Sort(ElementType n[], int num);
void Swap(ElementType *a, ElementType *b);
int main()
{
	int num;
	float sum;
	float score[100];
	float result;
	while (scanf("%d", &num) != EOF){
		sum = 0;
		for (int i = 0; i < num; i++){
			scanf("%f", &score[i]);
		}
		Select_Sort(score, num);
		for (int i = 1; i < num - 1; i++){
			sum += score[i];
		}
		result = (float)(sum / (num - 2.0));
		printf("%.2f\n", result);
	}
}

//排序
void Select_Sort(ElementType n[], int num)
{
	for (int i = 0; i < num; i++){
		for (int j = i; j < num; j++){
			if (n[i] > n[j])
				Swap(&n[i], &n[j]);
		}
	}
}
void Swap(ElementType *a, ElementType *b)
{
	ElementType temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

  

HDU 2014

原文:http://www.cnblogs.com/mrethan/p/4152110.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!