## 2013年8月15日

### UVa 10258 - Contest Scoreboard

```#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;

struct CmpByAbs {
bool operator()(const double a, const double b) const {
return abs(a) < abs(b);
}
};

struct Contestant {
Contestant() {
memset(ac, 0, sizeof(ac));
}
Contestant(int id) : id(id) {}
bool operator<(const Contestant & other) const {
if (solved != other.solved) {
return solved > other.solved;
}
if (penalty != other.penalty) {
return penalty < other.penalty;
}
return id < other.id;
}
void judge() {
solved = penalty = 0;
for (int i = 0; i < 10; i++) {
if (!ac[i]) {
continue;
}
solved++;
sort(times[i].begin(), times[i].end(), CmpByAbs());
for (int j = 0; j < times[i].size(); j++) {
if (times[i][j] < 0) {
penalty += 20;
} else {
penalty += times[i][j] / 10;
break;
}
}
}
}
int id, solved, penalty;
bool ac[10];
vector<double> times[10];
};

int main() {
char s[99];
int T;
gets(s);
sscanf(s, "%d", &T);
gets(s);
while (T--) {
Contestant all[101];
bool submit[101] = {};
for (int i = 0; i < 101; i++) {
all[i].id = i;
}
int id, p, time, order = 1;
char status[2];
while (gets(s) && s[0]) {
sscanf(s, "%d%d%d%s", &id, &p, &time, status);
submit[id] = true;
if (status[0] == 'C') {
all[id].ac[p] = true;
all[id].times[p].PB(time * 10 + order * 0.1);
} else if (status[0] == 'I') {
all[id].times[p].PB(-(time * 10 + order * 0.1));
}
order++;
}
for (int i = 0; i < 101; i++) {
all[i].judge();
}
sort(all, all + 101);
for (int i = 0; i < 101; i++) {
if (submit[all[i].id]) {
printf("%d %d %d\n", all[i].id, all[i].solved, all[i].penalty);
}
}
if (T) {
puts("");
}
}
return 0;
}
```