题目
![]()
解法1
点击查看代码
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cmath>
using namespace std;
struct School {
string name;
double tws = 0.0; // 总加权分数
int ns = 0; // 考生人数
int rank = 1; // 排名
};
string toLower(string s) {
for (char &c : s)
if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
return s;
}
int main() {
int n; cin >> n;
unordered_map<string, School> schools;
for (int i = 0; i < n; ++i) {
string id, name; int score;
cin >> id >> score >> name;
name = toLower(name);
double weighted_score = 0.0;
if (id[0] == 'A') weighted_score = score;
else if (id[0] == 'B') weighted_score = score / 1.5;
else if (id[0] == 'T') weighted_score = score * 1.5;
schools[name].name = name;
schools[name].tws += weighted_score;
schools[name].ns += 1;
}
vector<School> schoolList;
for (auto it : schools) {
it.second.tws = floor(it.second.tws); // 取整数部分
schoolList.push_back(it.second);
}
sort(schoolList.begin(), schoolList.end(), [](const School &a, const School &b) {
if (a.tws != b.tws) return a.tws > b.tws;
else if (a.ns != b.ns) return a.ns < b.ns;
else return a.name < b.name;
});
cout << schoolList.size() << endl;
for (int i = 0; i < schoolList.size(); ++i) {
if (i > 0 && schoolList[i].tws == schoolList[i - 1].tws) {
schoolList[i].rank = schoolList[i - 1].rank;
} else {
schoolList[i].rank = i + 1;
}
cout << schoolList[i].rank << " " << schoolList[i].name << " "
<< int(schoolList[i].tws) << " " << schoolList[i].ns << endl;
}
return 0;
}