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;
    }
    低调做人,高调做事。
  • 相关阅读:
    HDU3336 Count the string —— KMP next数组
    CodeForces
    51Nod 1627 瞬间移动 —— 组合数学
    51Nod 1158 全是1的最大子矩阵 —— 预处理 + 暴力枚举 or 单调栈
    51Nod 1225 余数之和 —— 分区枚举
    51Nod 1084 矩阵取数问题 V2 —— 最小费用最大流 or 多线程DP
    51Nod 机器人走方格 V3 —— 卡特兰数、Lucas定理
    51Nod XOR key —— 区间最大异或值 可持久化字典树
    HDU4825 Xor Sum —— Trie树
    51Nod 1515 明辨是非 —— 并查集 + 启发式合并
  • 原文地址:https://www.cnblogs.com/Asimple/p/5912998.html
Copyright © 2011-2022 走看看