A1028 List Sorting

摘要
Title: A1028 List Sorting
Tag: 排序
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

A1028 List Sorting

  • 题意

    Excel can sort records according to any column. Now you are supposed to imitate this function.

  • 思路

    排序

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    /*
    * @Author: NEFU AB-IN
    * @Date: 2023-01-07 17:43:29
    * @FilePath: \GPLT\A1028\A1028.cpp
    * @LastEditTime: 2023-01-07 17:47:38
    */
    #include <bits/stdc++.h>
    using namespace std;
    #define N n + 100
    #define int long long
    #define SZ(X) ((int)(X).size())
    #define IOS \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr)
    #define DEBUG(X) cout << #X << ": " << X << '\n'
    typedef pair<int, int> PII;

    // #undef N
    // const int N = 1e5 + 10;

    // #undef int

    struct sa
    {
    string id, name;
    int grade;
    };

    signed main()
    {
    IOS;
    vector<sa> a;

    int n, c;
    cin >> n >> c;
    for (int i = 1; i <= n; ++i)
    {
    string id, name;
    int grade;
    cin >> id >> name >> grade;
    a.push_back({id, name, grade});
    }
    sort(a.begin(), a.end(), [&](const sa a, const sa b) {
    if (a.name != b.name && c == 2)
    return a.name < b.name;
    if (a.grade != b.grade && c == 3)
    return a.grade < b.grade;
    return a.id < b.id;
    });

    for (auto &[id, name, grade] : a)
    {
    cout << id << " " << name << " " << grade << '\n';
    }

    return 0;
    }
使用搜索:谷歌必应百度