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;
}
相关推荐
西京刀客1 天前
MySQL字符集排序规则冲突问题(utf8mb4_unicode_ci和utf8mb4_0900_ai_ci )
mysql·排序·utf8mb4
GHZhao_GIS_RS2 天前
python中的sort和sorted用法汇总
python·排序·列表
码农幻想梦2 天前
3446. 整数奇偶排序
排序
码农幻想梦2 天前
3376. 成绩排序2
排序
Tisfy4 天前
LeetCode 3651.带传送的最小路径成本:动态规划
算法·leetcode·动态规划·题解·排序
2401_8414956411 天前
【Python高级编程】单词统计与查找分析工具
数据结构·python·算法·gui·排序·单词统计·查找
2401_8414956412 天前
【数据结构】英文单词词频统计与检索系统
数据结构·c++·算法·排序·词频统计·查找·单词检索
Tisfy17 天前
LeetCode 2943.最大化网格图中正方形空洞的面积:小小思维
算法·leetcode·题解·数组·思维·排序·连续
汉克老师1 个月前
GESP2025年12月认证C++五级真题与解析(判断题1-10)
c++·链表·贪心算法·排序·gesp5级·gesp五级