题目
思路
简单排序题
代码
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <string.h>
using namespace std;
struct info {
double sum;
int ans;
int num;
int rank;
};
unordered_map<string, info> m;
bool cmp(const pair<string, info>& a, const pair<string, info>& b) {
if (a.second.ans != b.second.ans)
return a.second.ans > b.second.ans;
else {
if (a.second.num != b.second.num)
return a.second.num < b.second.num;
else
return a.first < b.first;
}
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string pname, sname;
double score;
cin >> pname >> score >> sname;
switch (pname[0]){
case 'T':
score *= 1.5;
break;
case 'B':
score /= 1.5;
break;
}
transform(sname.begin(), sname.end(),sname.begin(),::tolower);
auto p = m.find(sname);
if (p != m.end()) {
p->second.num++;
p->second.sum += score;
}
else
m.emplace(pair<string, info>(sname, info{ score,0,1,0 }));
}
for (auto& p : m)
p.second.ans = (int)p.second.sum;
vector<pair<string, info>> vec(m.begin(), m.end());
sort(vec.begin(), vec.end(), cmp);
cout << vec.size() << endl;
for (int i = 0; i < vec.size();++i) {
if (i != 0 && vec[i].second.ans == vec[i - 1].second.ans)
vec[i].second.rank = vec[i - 1].second.rank;
else
vec[i].second.rank = i + 1;
cout << vec[i].second.rank << " " << vec[i].first << " " << vec[i].second.ans << " " <<vec[i].second.num << endl;
}
return 0;
}