zoukankan      html  css  js  c++  java
  • 每日一九度之 题目1061:成绩排序

    时间限制:1 秒

    内存限制:32 兆

    特殊判题:

    提交:22287

    解决:6281

    题目描述:

        有N个学生的数据,将学生数据按成绩高低排序,如果成绩相同则按姓名字符的字母序排序,如果姓名的字母序也相同则按照学生的年龄排序,并输出N个学生排序后的信息。

    输入:

        测试数据有多组,每组输入第一行有一个整数N(N<=1000),接下来的N行包括N个学生的数据。
        每个学生的数据包括姓名(长度不超过100的字符串)、年龄(整形数)、成绩(小于等于100的正数)。

    输出:

        将学生信息按成绩进行排序,成绩相同的则按姓名的字母序进行排序。
        然后输出学生信息,按照如下格式:
        姓名 年龄 成绩

    样例输入:
    3
    abc 20 99
    bcd 19 97
    bed 20 97
    样例输出:
    bcd 19 97
    bed 20 97
    abc 20 99
    提示:

    学生姓名的字母序区分字母的大小写,如A要比a的字母序靠前(因为A的ASC码比a的ASC码要小)。

    做了七八道题,终于做来了一道稍微有点难度的题,其实也挺简单的。

    但是,排序还是需要掌握的,很重要,像PAT团体赛里面必有一道类似于这样的排序签到题。

    //Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <cctype>
    #include <cstdlib>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <map>
    #include <string>
    #include <queue>
    #include <limits.h>
    #define INF 0x7fffffff
    using namespace std;
    const int maxn = 105;
    typedef long long ll;
    int n;
    typedef struct node{
        char name[maxn];
        int age;
        int grade;
        bool operator < (const node& A) const{
            if( A.grade == grade ){
                if( strcmp(A.name,name) == 0 ){
                    return A.age > age;
                }
                return strcmp(A.name,name) > 0;
            }
            return A.grade>grade;
        }
    }student;
    student Stu[1005];
     
    int main(){
        while( ~scanf("%d",&n) ){
            for(int i=0; i<n; i++){
                scanf("%s %d %d",Stu[i].name,&Stu[i].age,&Stu[i].grade);
            }
            sort(Stu,Stu+n);
            for(int i=0; i<n; i++){
                printf("%s %d %d
    ",Stu[i].name,Stu[i].age,Stu[i].grade);
            }
        }
        return 0;
    }
    低调做人,高调做事。
  • 相关阅读:
    小知识
    对NSArray中自定义的对象进行排序
    照片浏览滑动效果UIScrollView和UIPageControl组合
    label 设置行间距 字间距
    即使通讯聊天界面搭建----iOS
    ios8推送新增
    UITableviewCell滑动出现多级的控制按钮
    iOS 去掉html标签 留下原本的字符串
    平时常用的小知识点 (不断更新中)
    IOS UI多线程 NSThread 下载并显示图片到UIImageView
  • 原文地址:https://www.cnblogs.com/Asimple/p/5912998.html
Copyright © 2011-2022 走看看