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;
}
相关推荐
aqiu11111111 天前
【算法刷题】蓝桥杯/AtCoder:删除元素后的中位数问题(Symmetry / Median)
算法·蓝桥杯·排序·中位数
aqiu11111113 天前
【算法刷题】蓝桥杯:0星际争霸(大数比较 + 多关键字自定义排序)
算法·排序·自定义排序
aqiu11111117 天前
【算法刷题】蓝桥杯:怎么倒茶(贪心算法 + 结构体排序)
贪心·排序
OuO-217 天前
笔试强训 Day 43:kotori 和抽卡(二)、ruby 和薯条、循环汉诺塔
数学·前缀和·二分查找·动态规划·排序·滑动窗口·循环汉诺塔
Tisfy21 天前
LeetCode 3731.找出缺失的元素:哈希 / 排序
算法·leetcode·哈希算法·排序·哈希表
Tisfy1 个月前
LeetCode 3016.输入单词需要的最少按键次数 II:排序(贪心)
linux·算法·leetcode·题解·贪心·排序·计数
Tisfy1 个月前
LeetCode 3517.最小回文排列 I:排序(Python两行版) / 计数(O(n)时间+O(C)空间+字符串原地修改)
c语言·python·leetcode·字符串·排序·计数排序·回文
txzrxz1 个月前
拓补排序讲解
c++·算法·图论·排序
汉克老师2 个月前
GESP2026年6月认证C++八级( 第三部分编程题(1、线网建设))精讲
c++·最小生成树·排序·kruskal·并查集·gesp8级
Tisfy2 个月前
LeetCode 1288.删除被覆盖区间:排序(非二重循环暴力)
算法·leetcode·题解·排序