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;
}
相关推荐
汉克老师11 天前
GESP5级C++考试语法知识(十四、分治算法(一))
算法·归并排序·排序·分治算法·gesp5级·gesp五级
汉克老师16 天前
GESP2025年3月认证C++五级( 第三部分编程题(1、平均分配))
c++·算法·贪心算法·排序·gesp5级·gesp五级
Irene199121 天前
数据排序为什么默认升序
算法·排序
浅念-22 天前
分治算法专题|LeetCode高频经典题目详细题解
数据结构·c++·算法·leetcode·职场和发展·排序·分治
漂流瓶jz1 个月前
UVA-120 煎饼 题解答案代码 算法竞赛入门经典第二版
数据结构·c++·算法·排序·aoapc·算法竞赛入门经典·uva
闻缺陷则喜何志丹1 个月前
【排序 离散化 二维前缀和】 P7149 [USACO20DEC] Rectangular Pasture S|普及+
c++·算法·排序·离散化·二维前缀和
闻缺陷则喜何志丹1 个月前
【排序】P6149 [USACO20FEB] Triangles S|普及+
c++·算法·排序·洛谷
Tairitsu_H1 个月前
C语言:排序(一)
c语言·数据结构·排序
起个破名想半天了1 个月前
算法与数据结构之排序
数据结构·排序算法·排序·算法与数据结构
问好眼2 个月前
《算法竞赛进阶指南》0x05 排序-1.电影
c++·算法·排序·信息学奥赛