题解 | #小白鼠排队#

小白鼠排队

https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b

//习题3.3 小白鼠排队
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;

struct Mouse{
    int weight;
    string color;
};

bool comp(Mouse x,Mouse y){
    if (x.weight>=y.weight){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    int n;
    while(scanf("%d",&n) != EOF){
        Mouse mouse1[n];
        for (int i=0;i<n;i++){
            cin>>mouse1[i].weight>>mouse1[i].color;
        }
        sort(mouse1,mouse1+n,comp);
        for (int i=0;i<n;i++){
            cout<<mouse1[i].color<<endl;
        }
    }
    return 0;
}

全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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