我的个人网站 Cheese的个人主页http://www.cheese.ren/
博客来源 PAT 乙级 1085 PAT单位排行-Cheese的个人博客http://blog.cheese.ren/105
欢迎交换友链 :-)
#include <bits/stdc++.h>
using namespace std;
struct School
{
double grade=0;
string name;
int student_count=0;
int score=0;
};
bool cmp(const pair<string, School> a, const pair<string, School> b) {
if (a.second.score != b.second.score) return a.second.score > b.second.score;
else if (a.second.student_count != b.second.student_count) return a.second.student_count < b.second.student_count;
else return a.second.name < b.second.name;
}
int main() {
int n;
cin >> n;
map<string, School> schools;
while (n--) {
char id[7];
string school;
double grade;
cin >> id >> grade >> school;
if (id[0] == 'B')
grade /= 1.5;
else if (id[0] == 'T')
grade *= 1.5;
for (int i=0; i<school.length(); i++)
if (school[i] >= 'A' && school[i] <= 'Z')
school[i] += 32;
schools[school].name = school;
schools[school].grade += grade;
schools[school].student_count++;
}
for (map<string, School>::iterator i=schools.begin(); i!=schools.end(); i++)
i->second.score = (int)i->second.grade;
vector<pair<string, School>> schools_ranking(schools.begin(), schools.end());
sort(schools_ranking.begin(), schools_ranking.end(), cmp);
cout << schools_ranking.size() << endl;
int ranking=1, score_temp=schools_ranking[0].second.score;
for (int i=0; i<schools_ranking.size(); i++) {
if (schools_ranking[i].second.score != score_temp) {
ranking = i + 1;
score_temp = schools_ranking[i].second.score;
}
cout << ranking << " " << schools_ranking[i].second.name << " " << schools_ranking[i].second.score << " " << schools_ranking[i].second.student_count << endl;
}
return 0;
}