题意:给出一些学校的成绩,比赛的层次,分数,输出学校的排名,分数,人数。
思路:排序就好。
代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
const int MAX_N = 100010;
struct Data {
string sch;
double grade;
int cnt;
bool operator < (const Data& d) const {
return (int)grade>(int)d.grade || ((int)grade==(int)d.grade && cnt < d.cnt) ||
((int)grade==(int)d.grade && cnt==d.cnt && sch < d.sch);
}
}d[MAX_N];
char a[100], b[100];
int gr, n;
vector<string> v;
map<string, int> id;
int get_id(string x) {
if (id.count(x)) return id[x];
v.push_back(x);
return id[x] = v.size()-1;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %d %s", a, &gr, b); int len = strlen(b);
double tmp = 0.0;
if (a[0] == 'A') tmp = gr;
else if (a[0] == 'B') tmp = 1.0*gr/1.5;
else if (a[0] == 'T') tmp = 1.5*gr;
for(int j = 0; j < len; j++) b[j]=tolower(b[j]);
int t = get_id(b);
d[t].cnt++; d[t].grade+=tmp; d[t].sch=b;
}
sort(d, d+v.size());
int ind = 0, ct = 1, la = -1;
printf("%lu\n", v.size());
for (int i = 0; i < v.size(); i++) {
if (la == (int)d[i].grade) ct++;
else {
ind += ct; ct = 1; la = (int)d[i].grade;
}
printf("%d %s %d %d\n", ind, d[i].sch.c_str(), (int)d[i].grade, d[i].cnt);
}
return 0;
}