使用map<string, int>
进行institution与编号的映射
模拟排序的题目,要细心get所有的排序条件啊
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
const int N = 100010;
map<string, int>myMap;
int n, cnt;
struct node {
char name[10];
int cnt;
int A;
int B;
int T;
int TWS;
};
node school[N];
int cmp(const node& A, const node& B) {
if (A.TWS != B.TWS) return A.TWS > B.TWS;
else if (A.cnt != B.cnt) return A.cnt < B.cnt;
else return strcmp(A.name, B.name) < 0;
}
void ToLower(char* s) {
for (int i = 0; i < strlen(s); ++i)
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = 'a' + s[i] - 'A';
}
int main()
{
scanf("%d", &n);
char id[10];
int s;
char sch[10];
cnt = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s%d%s", &id, &s, &sch);
ToLower(sch);
if (myMap[sch] == 0) {
myMap[sch] = ++cnt;
strcpy(school[cnt].name, sch);
school[cnt].cnt = 0;
school[cnt].A = 0;
school[cnt].B = 0;
school[cnt].T = 0;
school[cnt].TWS = 0;
}
if (id[0] == 'B') school[myMap[sch]].B += s;
else if (id[0] == 'A') school[myMap[sch]].A += s;
else school[myMap[sch]].T += s;
school[myMap[sch]].cnt++;
}
for (int i = 1; i <= cnt; ++i) {
double sc = (double)school[i].B / 1.5 + (double)school[i].A + (double)school[i].T * 1.5;
school[i].TWS = floor(sc);
}
sort(school + 1, school + 1 + cnt, cmp);
int rk = 1;
int last = school[1].TWS;
printf("%d\n", cnt);
for (int i = 1; i <= cnt; ++i) {
if (school[i].TWS < last) {
rk = i;
last = school[i].TWS;
}
printf("%d %s %d %d\n", rk, school[i].name, school[i].TWS, school[i].cnt);
}
return 0;
}