题解 | #小白鼠排队#比较器只能返回true和false!

小白鼠排队

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

#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;

struct Mouse {
    char color[20];
    int weight;
};

bool compare(Mouse m1, Mouse m2) {
    if (m1.weight - m2.weight >= 0) {
        return true;
    } else {
        return false;
    }

}

Mouse mouse[120];

int main() {
    int N;
    while (scanf("%d", &N) != EOF) {
        for (int i = 0; i < N; i++) {
            scanf("%d %s", &mouse[i].weight, mouse[i].color);
        }
        sort(mouse, mouse + N, compare);
        for (int i = 0; i < N; i++) {
            printf("%s\n", mouse[i].color);
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛客771574427号:恭喜你,华杰
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务