Description
The past 2012 to small q is a very sad reminder of a year, lovelorn 12 times, every time to be depressed 1 months.
Fortunately, little Q is a sports fan, in the most painful times, he often use to watch various sports programs to anesthesia himself, such as the London Olympics, small q often on the weekend invited a group of single colleagues gathered in their own dwelling, while drinking beer, while bragging.
Small Q Most like to see is diving, the main reason is because the project has the Chinese to participate, and Chinese players have a great chance of winning, generally will not add to their own plugging, or how to talk about physical therapy injury.
An important part of the diving project is the referee scoring, small Q they sometimes feel that a referee is unfair, is not intentionally in the pressure of Chinese players score. So every time a player dives, they are like the referee on the TV to score the players, and rules, who scores and final score closest to who is the best referee among them, on-site award beer a cup!
Among them, the final score is calculated as: N Individual score, remove a maximum score, remove a minimum score, then add the remaining points, divided by N-2 is the final score.
By virtue of "watching sports therapy injury" and trained professional sports knowledge, small Q almost every win, this night, small q is doomed to be drunk ...
Input
The input contains multiple sets of test cases.
Each set of test cases is first an integer n, representing the number of referees, followed by n real numbers, indicating that the score of n pi,n is 0 o'clock end input.
[Technical specification]
5 <= N <= 20
0<=pi<=10
Output
Please calculate and output the number of the best referee, each set of data output for one row, if there are more than the best referee, only the one with the lowest output number.
Special Note: The ref number starts from 1 in the order of scoring, and so on, and the last person is numbered n.
Sample Input
5 8.3 9.2 8.7 8.9 9.00
Sample Output
4 AC Code:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace Std;
int main ()
{
int N,flag;
Double a[20],max,sum,min,ave,x;
while (~SCANF ("%d", &n))
{
if (n==0| | N<5) break;
for (int i=0;i<n;i++)
scanf ("%lf", &a[i]);
max=-999;
min=999;
sum=0;
for (int i=0;i<n;i++)
{
if (Max<a[i]) max=a[i];
if (Min>a[i]) min=a[i];
Sum+=a[i];
}
Ave= (sum-max-min)/(n-2);
x=999;
for (int i=0;i<n;i++)
{
if (X>fabs (Ave-a[i]))
{
X=fabs (Ave-a[i]);
Flag=i;
}
}
printf ("%d\n", flag+1);
}
return 0;
}
Experience: This problem is a water problem, so simple I did not do it, really want to smoke their two ears, but also from the aspect of the content of their own grasp of the incomplete, this is a use for the loop to solve the problem, it seems to spend time to review the knowledge of the previous learning. It's really a pit.
C-Small Q series Story--The best referee