Question:
1. In a diving competition, eight judges scored the score. The score for an athlete was 8. The highest score and the lowest score were removed. The average score of the remaining six scores is the final score. Use a one-dimensional array for scoring.
2. Find the judges with the highest and lowest scores.
Solution:
The first page:
< Html > < Head > < Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = UTF-8" > </ Head > < Body > < H1 > Ask the referee to enter the score </ H1 > < Form Action = "Result02.php" Method = "Post" > Referee 1 < Input Type = "Text" Name = "One" > < BR /> Referee 2 < Input Type = "Text" Name = "Two" > < BR /> Referee 3 < Input Type = "Text" Name = "Three" > < BR /> Referee 4 < Input Type = "Text" Name = "Four" > < BR /> Referee 5 < Input Type = "Text" Name = "Five" > < BR /> Referee 6 < Input Type = "Text" Name = "Six" > < BR /> Referee 7 < Input Type = "Text" Name = "Seven" > < BR /> Referee 8 < Input Type = "Text" Name = "Eight" > < BR /> < Input Type = "Submit" Value = "Submit" > </ Form > </ Body > </ Html >
Page 2: result02.php
<? PHP // Receive data $ P1 = $ _ Request ['One' ]; $ P2 = $ _ Request ['Two' ]; $ P3 = $ _ Request ['Three' ]; $ P4 = $ _ Request ['Four' ]; $ P5 = $ _ Request ['Five' ]; $ P6 = $ _ Request ['Six' ]; $ P7 = $ _ Request ['Seven' ]; $ P8 = $ _ Request ['Eight' ]; // Put the value entered by each person into the Array $ Arr = Array ($ P1 , $ P2 , $ P3 , $ P4 , $ P5 , $ P6 , $ P7 , $ P8 ); // Print_r ($ ARR); // retrieves the largest and smallest values. $ P_max = Max ( $ Arr ); $ P_min = Min ( $ Arr ); // Print_r ($ ARR); // echo $ p_max, $ p_min; // echo "<br/>"; // defines the total score of variable Calculation $ Total = 0 ; /* For ($ I = 0; $ I <count ($ ARR); $ I ++) {// echo $ arr [$ I]. "<br/>"; $ total + = $ arr [$ I];} */ Foreach ($ Arr As $ V ){ $ Total + = $ V ;} // Echo $ total. "<br/>"; // minus the highest score, the final score // average score // The round function retains the decimal place | this is a rounding method that retains three decimal places $ Last = ( $ Total - Max ( $ Arr )- Min ($ Arr ))/( Count ( $ Arr )-2 ); // $ Last = ($ total-max ($ ARR)-min ($ ARR )); Echo 'The last score except the highest score and lowest score is :'.( $ Total - Max ( $ Arr )- Min ( $ Arr ). "<Br/>" ; Echo 'The average score except the highest score and the lowest score is :'. Round ( $ Last , 3). "<br/>" ; // Find the key: array_search function mapped to the maximum and minimum values. $ Max_k = Array_search ( Max ( $ Arr ), $ Arr ); $ Min_k = Array_search (Min ( $ Arr ), $ Arr ); Echo 'The highest score is the nth '.( $ Max_k + 1). 'judge '. Max ( $ Arr ). 'Points <br/>' ; Echo 'Minute is the nth '.( $ Min_k + 1). 'judge '. Min ( $ Arr ). 'Points <br/>'; ?>