计蒜客_成绩排序

计蒜客_成绩排序

小蒜给出了班里某门课程的成绩单,请你按成绩从高到低对成绩单排序输出,如果有相同分数则名字字典序小的在前。

输入格式
第一行为 n(0 < n < 20),表示班里的学生数目;
接下来的 n行,每行为每个学生的名字和他的成绩, 中间用单个空格隔开。名字只包含字母且长度不超过 20,成绩为一个不大于 100 的非负整数。
输出格式
把成绩单按分数从高到低的顺序进行排序并输出,每行包含名字和分数两项,之间有一个空格。

样例输入

4
Kitty 80
Hanmeimei 90
Joey 92
Tim 28

样例输出

Joey 92
Hanmeimei 90 
Kitty 80
Tim 28
//main.cpp
#include <iostream>  
#include <string>  
#include <map>  
using namespace std;  
  
typedef struct tagStudentinfo  
{  
  
       int      Score;  
       string   strName;  
  
       bool operator < (tagStudentinfo const& _A) const  
       {     //这个函数指定排序策略,按成绩排序,如果成绩相等的话,按strName排序 
            if(Score > _A.Score) return true;  
            if(Score == _A.Score)  
                return strName.compare(_A.strName) < 0;  
        return false;  
       }  
  
}Studentinfo; //学生信息  
  
int main()    
{  
    int nSize;   //用学生分数映射学生姓名  
    map<Studentinfo, int>mapStudent;  
    map<Studentinfo, int>::iterator iter;  
    Studentinfo studentinfo;  
    int n=0;
    cin>>n;
    for(int i=0;i<n;i++){
    	string str;
    	int score;
    	cin>>str>>score;
    	studentinfo.Score = score;  
    	studentinfo.strName = str;  
    	mapStudent.insert(pair<Studentinfo, int>(studentinfo, 0)); 
    }
    for (iter=mapStudent.begin(); iter!=mapStudent.end(); iter++)   
        cout<<iter->first.strName<<' '<<iter->first.Score<<endl;  
    return 0;  
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高二的笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值