How to Use php to score judges and php to score judges

Source: Internet
Author: User

How to Use php to score judges and php to score judges

Use the selection sorting method to find the highest score and lowest score from the input array, and then remove the highest score and one lowest score to obtain the average score of the contestant.

1. Implementation Code

<? Phpfunction fairScore (& $ arr) {// select the first step of sorting. Here you only need to find the maximum and minimum values in this array, no need to sort the entire array $ minVal = $ arr [0]; $ minIndex = 0; $ maxVal = $ arr [0]; $ maxIndex = 0; $ sum = 0; for ($ I = 1; $ I <count ($ arr); $ I ++) {if ($ arr [$ I] <$ minVal) {$ minVal = $ arr [$ I]; $ minIndex = $ I;} if ($ arr [$ I]> $ maxVal) {$ maxVal = $ arr [$ I]; $ maxIndex = $ I ;}} echo "highest score :". $ maxVal. "Min :". $ minVal. "<br/>"; for ($ I = 0; $ I <count ($ arr); $ I ++) {$ sum + = $ Arr [$ I] ;}$ sum-= ($ minVal + $ maxVal); echo "Total ". count ($ arr ). "judges, the average score after removing the highest score and lowest score is ". $ sum/(count ($ arr)-2);} $ score = @ $ _ REQUEST ['score ']; // when the page is opened for the first time, no data is input, therefore, it cannot be submitted. Add @ here to remove the browser notice warning $ aScore = explode ("", $ score);?> <Html> 

2. Run

The above is all the content of this article, and I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.