solution
- 测试点5:总分是在每个学生加权后再取整,所以用来存学生分数的变量要用浮点型
- 学校排序:
- 若成绩不同,则按成绩降序
- 若成绩相同,人数不同,则按成绩升序
- 若成绩和人数都相同,则按单位名升序
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int maxn = 1e5 + 100;
struct depart{double score = 0;string id;int cnt = 0;friend bool operator < (depart &d1, depart &d2){if((int)d1.score != (int)d2.score) return d1.score > d2.score;else if(d1.cnt != d2.cnt) return d1.cnt < d2.cnt;return d1.id < d2.id;}
}ds[maxn];
int main(){string id, sc;int n, num = 0, order = 1;double score;unordered_map<string, int> mp;cin >> n;for(int i = 0; i < n; i++){cin >> id >> score >> sc;transform(sc.begin(), sc.end(), sc.begin(), ::tolower);if(!mp.count(sc)) {mp[sc] = num;ds[num++].id = sc;}if(id[0] == 'B') score = score / 1.5;else if(id[0] == 'T') score = score * 1.5;ds[mp[sc]].score += score;ds[mp[sc]].cnt++;}sort(ds, ds + num);cout << num << endl;for(int i = 0; i < num; i++){if(i != 0 && (int)ds[i].score != (int)ds[i - 1].score) order = i + 1;cout << order << " " << ds[i].id << " " << (int)ds[i].score << " " << ds[i].cnt << endl;}return 0;
}
or
#include<iostream>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int maxn = 1e5 + 100;
struct depart{double score = 0;string id;int cnt = 0;friend bool operator < (depart &d1, depart &d2){if(d1.score != d2.score) return d1.score > d2.score;else if(d1.cnt != d2.cnt) return d1.cnt < d2.cnt;return d1.id < d2.id;}
}ds[maxn];
int main(){string id, sc;int n, num = 0, order = 1;double score;unordered_map<string, int> mp;cin >> n;for(int i = 0; i < n; i++){cin >> id >> score >> sc;transform(sc.begin(), sc.end(), sc.begin(), ::tolower);if(!mp.count(sc)) {mp[sc] = num;ds[num++].id = sc;}if(id[0] == 'B') score = score / 1.5;else if(id[0] == 'T') score = score * 1.5;ds[mp[sc]].score += score;ds[mp[sc]].cnt++;}for(int i = 0; i < num; i++) ds[i].score = (int) ds[i].score;sort(ds, ds + num);cout << num << endl;for(int i = 0; i < num; i++){if(i != 0 && ds[i].score != ds[i - 1].score) order = i + 1;cout << order << " " << ds[i].id << " " << ds[i].score << " " << ds[i].cnt << endl;}return 0;
}