//题目意思比较容易看懂,在这里不说了//不明白的是为什么用sort排序不行,而用qsort好使呢?想不同啊~~~//一开始我的输出听复杂的,后来看了他们(就是代码中的),感觉比我的好,就用了//感觉这里没啥好解释的,一看就能看明白,所以这次没加注释了!
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int testcase;
struct Problem{
char teamName[15];
int p[7],total_time,sum,g_m;
}problem[20];
int cmp(const void *_a, const void *_b)
{
struct Problem *a, *b;
a = (struct Problem *)_a;
b = (struct Problem *)_b;
if (a->sum != b->sum)
return b->sum - a->sum;
if (b->total_time != a->total_time)
return a->total_time - b->total_time;
if (b->g_m != a->g_m)
return a->g_m - b->g_m;
return strcmp(a->teamName, b->teamName);
}
void solve()
{
int i,j;
for(i = 0;i < testcase;i++)
{
int count = 0;
int total = 0;
double gm = 1;
for(j = 0;j < 7;j++)
{
if(problem[i].p[j] != 0)
{
count++;
total += problem[i].p[j];
gm *= problem[i].p[j];
}
}
problem[i].sum = count;
problem[i].total_time = total;
if(count)
problem[i].g_m = (int)(pow(gm,1.0/count) + 0.5);
else
problem[i].g_m = 0;
}
qsort(problem, testcase, sizeof(problem[0]), cmp);
}
void output()
{
int i,j,r;
for(i = 0,r = 0;i < testcase;i++)
{
if(i && (problem[i].sum != problem[i-1].sum) || (problem[i].total_time != problem[i-1].total_time) || (problem[i].g_m != problem[i-1].g_m))
r = i;
printf("%.2d %-10s%2d%5d%4d",r+1,problem[i].teamName,problem[i].sum,problem[i].total_time,problem[i].g_m);
for(j = 0;j < 7;j ++)
printf("%4d",problem[i].p[j]);
printf("\n");
}
}
int main()
{
int i,j;
int account = 0;
while(cin>>testcase && testcase)
{
for(i = 0;i < testcase;i++)
{
cin>>problem[i].teamName;
for(j = 0;j < 7;j++)
{
cin>>problem[i].p[j];
}
}
solve();
printf("CONTEST %d\n", ++account);
output();
}
return 0;
}