📄 1626.cpp
字号:
/* This Code is Submitted by wywcgs for Problem 1626 on 2005-12-05 at 16:33:15 */
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
const int QUES_N = 7;
const int L_MAX = 32;
class Team {
public:
char name[L_MAX];
int sloved;
int time[QUES_N], total, aver;
void init();
void print(int) const;
bool operator !=(const Team&) const;
};
void Team::init() {
int i;
long long mutl = 1;
scanf("%s", name);
total = sloved = 0;
for(i = 0; i < QUES_N; i++) {
scanf("%d", &time[i]);
total += time[i];
if(time[i] != 0) {
sloved++;
mutl *= time[i];
}
}
if(sloved == 0) {
aver = 0;
} else {
aver = (int)(pow((double)mutl, 1/(double)sloved) + 0.5);
}
}
void Team::print(int n) const {
if(n < 10) {
putchar('0');
}
printf("%d %-10s %d %4d %3d", n, name, sloved, total, aver);
int i;
for(i = 0; i < QUES_N; i++) {
printf(" %3d", time[i]);
}
putchar('\n');
}
bool Team::operator !=(const Team& t) const {
return !((sloved == t.sloved) && (total == t.total) && (aver == t.aver));
}
int cmp(const void*, const void*);
int main()
{
Team team[L_MAX];
int t, n;
int i;
for(t = 1; scanf("%d", &n) == 1 && n != 0; t++) {
for(i = 0; i < n; i++) {
team[i].init();
}
qsort(team, n, sizeof(Team), cmp);
printf("CONTEST %d\n", t);
int curo;
for(i = 0; i < n; i++) {
if(i == 0 || team[i] != team[i-1]) {
curo = i + 1;
}
team[i].print(curo);
}
}
return 0;
}
int cmp(const void* a, const void* b)
{
Team *x = (Team*)a, *y = (Team*)b;
if(x->sloved != y->sloved) {
return (y->sloved - x->sloved);
} else if(x->total != y->total) {
return (x->total - y->total);
} else if(x->aver != y->aver) {
return (x->aver - y->aver);
} else {
return strcmp(x->name, y->name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -