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;
}
相关推荐
问好眼7 天前
《算法竞赛进阶指南》0x05 排序-1.电影
c++·算法·排序·信息学奥赛
汉克老师12 天前
GESP2026年3月认证C++五级( 第三部分编程题(2)找数)
c++·排序·双指针·二分算法·gesp5级·gesp五级
伟大的车尔尼13 天前
双指针题目:满足条件的子序列数目
二分查找·排序·双指针
AKA__Zas1 个月前
初识基本排序
java·数据结构·学习方法·排序
元亓亓亓1 个月前
考研408--数据结构--day15--排序&内部排序(上)
数据结构·408·排序·内部排序
闻缺陷则喜何志丹2 个月前
【前后缀分解 排序】B4274 [蓝桥杯青少年组省赛 2023] 数字游戏|普及+
c++·蓝桥杯·排序·洛谷·前后缀分解
知无不研2 个月前
冒泡排序算法
算法·冒泡排序·排序
Tisfy2 个月前
LeetCode 3010.将数组分成最小总代价的子数组 I:排序 OR 维护最小次小
算法·leetcode·题解·排序·最小次小值
西京刀客2 个月前
MySQL字符集排序规则冲突问题(utf8mb4_unicode_ci和utf8mb4_0900_ai_ci )
mysql·排序·utf8mb4