1028 List Sorting (25 分) 难度: 简单 / 知识点: 排序

Posted 辉小歌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1028 List Sorting (25 分) 难度: 简单 / 知识点: 排序相关的知识,希望对你有一定的参考价值。


https://pintia.cn/problem-sets/994805342720868352/problems/994805468327690240

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m;
struct node
{
    string name;
    int id,score;
}Node[N];
bool cmp1(node a,node b)
{
    return a.id<b.id;
}
bool cmp2(node a,node b)
{
    if(a.name==b.name) return a.id<b.id;
    return a.name<b.name;
}
bool cmp3(node a,node b)
{
    if(a.score==b.score) return a.id<b.id;
    return a.score<b.score;
}
int main(void)
{
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>Node[i].id>>Node[i].name>>Node[i].score;
    if(m==1) sort(Node,Node+n,cmp1);
    else if(m==2) sort(Node,Node+n,cmp2);
    else sort(Node,Node+n,cmp3);
    for(int i=0;i<n;i++)
    {
        printf("%06d %s %d\\n",Node[i].id,Node[i].name.c_str(),Node[i].score);
    }
    return 0;
}

以上是关于1028 List Sorting (25 分) 难度: 简单 / 知识点: 排序的主要内容,如果未能解决你的问题,请参考以下文章

PAT 甲级 1028 List Sorting (25 分)(排序,简单题)

PAT Advanced 1028 List Sorting (25分)

1028 List Sorting (25 分) 难度: 简单 / 知识点: 排序

PAT甲级 1028 List Sorting (25分)(cin cout 超时问题)

PAT 1028 List Sorting

1028. List Sorting (25)