标签:
Description
Input
Output
Sample Input
Sample Output
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <math.h>
5
6 struct people
7 {
8 int num;
9 double fen;
10 }person [21];
11
12 using namespace std;
13 int main()
14 {
15 int N;
16 double all,temp,min;
17 int t;
18 int i,j,k;
19 while (scanf("%d",&N)&&N)
20 {
21 for (i=1;i<=N;i++)
22 {
23 scanf("%lf",&person[i].fen);
24 person[i].num=i;
25 }
26
27 for (i=1;i<=N;i++)
28 {
29 k=i;
30 for (j=i+1;j<=N;j++)
31 {
32 if (person[j].fen<person[k].fen)
33 {
34 k=j;
35 }
36 }
37 if (k!=i)
38 {
39 temp=person[k].fen;
40 person[k].fen=person[i].fen;
41 person[i].fen=temp;
42
43 t=person[k].num;
44 person[k].num=person[i].num;
45 person[i].num=t;
46 }
47 }
48 all=0;
49 for (i=2;i<=N-1;i++)
50 all+=person[i].fen;
51 all=all/(N-2);
52
53 k=person[1].num;
54 min=fabs(all-person[1].fen);
55 for (i=1;i<=N;i++)
56 {
57 if (fabs(all-person[i].fen)<=min)
58 {
59 if ((fabs(all-person[i].fen)==min)&&person[i].num<k)
60 {
61 k=person[i].num;
62 min=fabs(all-person[i].fen);
63 }
64 else if (fabs(all-person[i].fen)<min)
65 {
66 k=person[i].num;
67 min=fabs(all-person[i].fen);
68 }
69 }
70 }
71 printf("%d\n",k);
72 }
73 return 0;
74 }
标签:
原文地址:http://www.cnblogs.com/haoabcd2010/p/5696202.html