PKUKY109 小白鼠排队

PKUKY109 小白鼠排队

⭐️难度:简单

⭐️类型:排序

📖题目:题目链接

📚题解:

cpp 复制代码
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<vector>  // vector不需要.h
#include<list>
#include<set>  // // 可以用 set 和 multiset
#include<unordered_set> // 可以用 unordered_set 和 unordered_multiset
#include<map>  // 可以用 map 和 multimap
#include<unordered_map> // 可以用 unordered_map 和 unordered_multimap
#include<algorithm>

using namespace std;

struct shu {
    int weight;
    char color[10];
};

bool compare(shu lhs, shu rhs) {  // 倒序输出
    if (lhs.weight > rhs.weight) {
        return true;
    } else {
        return false;
    }
}
int main() {
    int n;
    scanf("%d", &n);

    vector<shu> vec(n);

    for (int i = 0; i < n; i++) {
        scanf("%d %s", &vec[i].weight, &vec[i].color);
    }

    sort(vec.begin(), vec.end(), compare);

    for (int i = 0; i < n; i++) {
        printf("%s\n", vec[i].color);
    }

    return 0;
}
相关推荐
元亓亓亓9 分钟前
考研408--数据结构--day15--排序&内部排序(上)
数据结构·408·排序·内部排序
闻缺陷则喜何志丹18 天前
【前后缀分解 排序】B4274 [蓝桥杯青少年组省赛 2023] 数字游戏|普及+
c++·蓝桥杯·排序·洛谷·前后缀分解
知无不研21 天前
冒泡排序算法
算法·冒泡排序·排序
Tisfy21 天前
LeetCode 3010.将数组分成最小总代价的子数组 I:排序 OR 维护最小次小
算法·leetcode·题解·排序·最小次小值
西京刀客22 天前
MySQL字符集排序规则冲突问题(utf8mb4_unicode_ci和utf8mb4_0900_ai_ci )
mysql·排序·utf8mb4
GHZhao_GIS_RS23 天前
python中的sort和sorted用法汇总
python·排序·列表
码农幻想梦23 天前
3446. 整数奇偶排序
排序
码农幻想梦23 天前
3376. 成绩排序2
排序
Tisfy25 天前
LeetCode 3651.带传送的最小路径成本:动态规划
算法·leetcode·动态规划·题解·排序