#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
//一个构造体保存账号,分数
struct student {
string id;
int score;
};
bool myCoop(student a, student b) {
if(a.score == b.score)
return a.id < b.id;
else
return a.score > b.score;
}
int main() {
int N,G,K;
cin>>N>>G>>K;
student s[N];
int money(0);
for(int i = 0; i < N; i++) {
cin>>s[i].id>>s[i].score;
if(s[i].score >= 60 && s[i].score < G)
money += 20;
else if(s[i].score >= G)
money += 50;
}
cout<<money<<endl;
sort(s, s+N, myCoop);
int rank = 1;//排名
int rerank = rank; //上一个排名
cout<<rank<<" "<<s[0].id<<" "<<s[0].score<<endl;
for(int i = 1; i < K; i++) {
if(s[i].score != s[i - 1].score) {
rank++;
rerank = rank;
cout<<rerank<<" "<<s[i].id<<" "<<s[i].score<<endl;
}
else {
rank++;
cout<<rerank<<" "<<s[i].id<<" "<<s[i].score<<endl;
}
}
for(int j = K; j < N; j++) {
if(s[j].score == s[K - 1].score) {
cout<<rerank<<" "<<s[j].id<<" "<<s[j].score<<endl;
}
else
break;
}
}
写一个结构体,新的排序,这些都不难,主要就是输出的时候,成绩相同的享有并列排名,比赛的时候没有完全做对。我的方法是用两个排名,一个排名是正常的排名(rank),只要输出就++,还有一个是上一个排名(renk),当分数和上一个相当时用rerank,否则更新rerank后再输出rerank