题解 | #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")

全部评论

相关推荐

找工作勤劳小蜜蜂:自我描述部分太差,完全看不出想从事什么行业什么岗位,也看不出想在哪个地区发展,这样 会让HR很犹豫,从而把你简历否决掉。现在企业都很注重员工稳定性和专注性,特别对于热爱本行业的员工。 你实习的工作又太传统的it开发(老旧),这部分公司已经趋于被淘汰,新兴的互联网服务业,比如物流,电商,新传媒,游戏开发和传统的It开发有天然区别。不是说传统It开发不行,而是就业岗位太少,基本趋于饱和,很多老骨头还能坚持,不需要新血液。 工作区域(比如长三角,珠三角,成渝)等也是HR考虑的因素之一,也是要你有个坚定的决心。否则去几天,人跑了,HR会被用人单位骂死。
点赞 评论 收藏
分享
UtopianYou...:这个简历排版真的不太行哦,去找免费的或者花点小钱,把排版弄整齐一点吧,看着舒服。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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