结构体排序

这是一个炒鸡水题,大佬们不要喷,但我确实容易忘。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct st{
    int n;
    float t;
};
struct st c[10];
bool duke(st a,st b)
{
    return a.t > b.t;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i = 0;i < t;i ++)
    {
        scanf("%d%g",&c[i].n,&c[i].t);
    }
    sort(c,c+t,duke);
    for(int i = 0;i < t;i++)
    {
        printf("%d %g
",c[i].n,c[i].t);
    }
    return 0;
}

虽然很简单,但是总是忘,所以在这里发布一下。#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct st{
    int n;
    float t;
};
struct st c[10];
bool duke(st a,st b)
{
    return a.t > b.t;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i = 0;i < t;i ++)
    {
        scanf("%d%g",&c[i].n,&c[i].t);
    }
    sort(c,c+t,duke);
    for(int i = 0;i < t;i++)
    {
        printf("%d %g
",c[i].n,c[i].t);
    }
    return 0;
}
只想找一个不会伤害我的人
原文地址:https://www.cnblogs.com/DukeLv/p/7995221.html