题解 | #EXCEL排序#

EXCEL排序

https://www.nowcoder.com/practice/bf3ec474bb7d410dbb9d5bbcd07a93e5

#include <iostream>
#include "algorithm"
using namespace std;
const int N = 1e5 + 10;
typedef struct Student
{
    string id, name;
    int score;
}Stu;
Stu stu[N];
static bool cmp1(const Stu& a, const Stu& b)
{
    return a.id < b.id;
}
static bool cmp2(const Stu& a, const Stu& b)
{
    if(a.name ==  b.name) 
        return a.id < b.id;
    return a.name < b.name;
}
static bool cmp3(const Stu& a, const Stu& b)
{
    if(a.score ==  b.score) 
        return a.id < b.id;
    return a.score < b.score;
}
int main() {
    int n, c;
    while (cin >> n >> c && n) { // 注意 while 处理多个 case
        for(int i = 0; i < n; i ++)
        {
            cin >> stu[i].id >> stu[i].name >> stu[i].score;
        }
        if(c == 1) sort(stu, stu + n, cmp1);
        else if(c == 2) sort(stu, stu + n, cmp2);
        else sort(stu, stu + n, cmp3);
        cout << "Case:\n";
        for(int i = 0; i < n; i ++)
        {
            cout << stu[i].id << ' ' << stu[i].name <<  ' ' << stu[i].score << endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:28
25届每天都在焦虑找工作的事情0offer情绪一直很低落硬撑着面了一个岗位岗位有应酬的成分面试的时候hr给我出各种场景题问的问题比较犀利&nbsp;有点压力面的感觉感觉有点回答不上来本来就压抑的情绪瞬间爆发了呢一瞬间特别想哭觉得自己特别没用没绷住掉眼泪了事后想想觉得自己挺有病的&nbsp;真的破大防了
喜欢唱跳rap小刺猬...:我觉得没关系吧,之前有一次面试leader给我压力面,我顶住了压力,结果入职的时候发现组里氛围很差,果断跑路。其实从面试就能大概看出组的情况,面试体验好的组倒是不一定好,但是面试体验不好的组。。。就很难说
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务