Home  >  Article  >  Backend Development  >  如何使用php实现评委评分器_PHP

如何使用php实现评委评分器_PHP

WBOY
WBOYOriginal
2016-05-30 08:47:231133browse

用选择排序法第一步从输入的数组中找到最高分和最低分,然后去掉一个最高分和一个最低分,得出选手的平均分。

1. 实现代码

<?php
function fairScore(&$arr)
{ //选择排序法的第一步,这里只需要找到这个数组中的最大值和最小值即可,没必要对整个数组排序
 $minVal = $arr[0];
 $minIndex = 0;
 $maxVal = $arr[0];
 $maxIndex = 0;
 $sum = 0;
 for ($i=1;$i$maxVal)
  {
   $maxVal = $arr[$i];
   $maxIndex = $i;
  }
 }
 echo "最高分是:".$maxVal." 最低分是:".$minVal."
"; for ($i=0;$i 去掉最高分和最低分后的平均分
请输入各个评委的打分,中间用空格隔开

<?php fairScore($aScore); ?>

2. 运行效果图

以上就是本文的全部内容,希望大家可以喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn