题解 | 小白鼠排队

小白鼠排队

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

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

struct Mouse {
    int weight;
    string color;
};

bool compare(Mouse lhs, Mouse rhs) {
    return lhs.weight > rhs.weight; // 从大到小排序
}

int main() {
    int n;
    cin >> n; // 使用 cin 读取 n
    vector<Mouse> vec(n);

    for (int i = 0; i < n; i++) {
        cin >> vec[i].weight >> vec[i].color; // 使用 cin 读取 weight 和 color
    }

    sort(vec.begin(), vec.end(), compare); // 排序

    for (int i = 0; i < n; i++) {
        cout << vec[i].color << endl; // 使用 cout 输出 color
    }

    return 0;
}

全部评论

相关推荐

06-07 00:00
已编辑
腾讯_后端开发
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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