这个题就是要注意下总成绩的格式问题,统计的时候要用double进行累加,排序前要转换成去掉小数部分的int。
#include <iostream>
#include <vector>
#include <map>
#include <cctype>
#include <algorithm>
using namespace std;
struct node{
string school;
int rank = 1, ns = 0; double tws = 0;
};
map<string, node> ma;
vector<node> v;
bool cmp(node a, node 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.school < b.school;
}
int main() {
int n; cin >> n;
for(int i = 0; i < n; i++){
string id, school; int score;
cin >> id >> score >> school;
for(int j = 0; j < school.length(); j++) school[j] = tolower(school[j]);
if(id[0] == 'A') ma[school].tws += score;
else if(id[0] == 'B') ma[school].tws += 1.0 * score / 1.5;
else ma[school].tws += 1.5 * score;
ma[school].school = school; ma[school].ns++;
}
for(auto it:ma){
it.second.tws = (int)(it.second.tws); v.push_back(it.second);
}
sort(v.begin(), v.end(), cmp);
printf("%d\n%d %s %d %d\n", v.size(), v[0].rank, v[0].school.c_str(), (int)v[0].tws, v[0].ns);
for(int i = 1; i < v.size(); i++){
if(v[i].tws == v[i-1].tws) v[i].rank = v[i-1].rank;
else v[i].rank = i + 1;
printf("%d %s %d %d\n", v[i].rank, v[i].school.c_str(), (int)v[i].tws, v[i].ns);
}
return 0;
}