题解 | #EXCEL排序#

EXCEL排序

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

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Student{
    string code;
    string name;
    int score;
    Student(string c,string n,int s):code(c),name(n),score(s){}
};

bool cmp1(Student a, Student b){
    return a.code < b.code;
}
bool cmp2(Student a, Student b){
    if(a.name==b.name){
        return a.code<b.code;
    }else{
        return a.name<b.name;
    }
    
}
bool cmp3(Student a, Student b){
    if(a.score==b.score){
        return a.code<b.code;
    }else{
        return a.score<b.score;
    }
}

int main() {
    int n,c,order=1;
    while(scanf("%d %d",&n,&c)!=EOF){
        vector <Student> s;
        vector <Student>::iterator it;
        int score;
        string name,code;
        for(int i=0;i<n;i++){
            cin>>code>>name>>score;
            s.push_back(Student(code,name,score));
        }
        if(c==1){
            sort(s.begin(),s.end(),cmp1);
        }else if(c==2){
             sort(s.begin(),s.end(),cmp2);
        } else if(c==3){
             sort(s.begin(),s.end(),cmp3);
        }
        printf("Case:\n",order++);
        for(it=s.begin();it!=s.end();it++){
            cout<<it->code<<" "<<it->name<<" "<<it->score<<endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
球球别再泡了:坏,我单9要了14
点赞 评论 收藏
分享
蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务