• 成绩排序


    总时间限制: 1000ms
    内存限制: 65536kB
    描述

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

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

    代码实现:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int n;
     6 struct nate{int point;char name[30];}s[30];
     7 int cmp(const nate &a,const nate &b){return a.point>b.point||(a.point==b.point&&strcmp(a.name,b.name)<0);}
     8 int main(){
     9     scanf("%d",&n);
    10     for(int i=1;i<=n;i++) scanf("%s%d",&s[i].name,&s[i].point);
    11     sort(s+1,s+n+1,cmp);
    12     for(int i=1;i<=n;i++) printf("%s %d
    ",s[i].name,s[i].point);
    13     return 0;
    14 }

    有一种苦逼的事情叫   突然发现自己连按字典序排序都不会了。

    题目来源:OpenJudge-NOI

  • 相关阅读:
    Leetcode: Find Median from Data Stream
    Leetcode: Flip Game II
    Leetcode: Flip Game
    Leetcode: Nim Game
    Leetcode: Word Pattern II
    Leetcode: Word Pattern
    Leetcode: Game of Life
    Leetcode: Alien Dictionary && Summary: Topological Sort
    Leetcode: Unique Word Abbreviation
    Leetcode: Find the Duplicate Number
  • 原文地址:https://www.cnblogs.com/J-william/p/6289424.html
Copyright © 2020-2023  润新知