1657

来源:互联网 发布:java 循环查询数据库 编辑:程序博客网 时间:2024/05/14 19:50
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define Max 20
using namespace std;
struct student
{
    int grade;
    char name[Max];
}s[105];
bool compare(const student s1, const student s2)
{
if (s1.grade > s2.grade)
    return true;
else if(s1.grade== s2.grade)
{
    if(strcmp(s1.name,s2.name)>0)
    return false;
else return true;
}
else return false;


}


int main()
{
    int T;


    while(~scanf("%d",&T))
    {
        for(int i=0;i<T;i++)
            cin>>s[i].name>>s[i].grade;
            sort(s,s+T,compare);
            for(int i=0;i<T;i++)
                cout<<s[i].name<<' '<<s[i].grade<<endl;
    }
    return 0;
}
0 0
原创粉丝点击