zoukankan      html  css  js  c++  java
  • 结构体排序

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

    #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;
    }
    只想找一个不会伤害我的人
  • 相关阅读:
    The AndroidManifest.xml File
    handlebars简单用法
    高性能跨语言模板引擎Crox
    C++17 新特性
    C++ 14新特性
    [lua]笔记
    [lua]笔记
    delphi关键字
    delphi 基础
    TCP/UDP
  • 原文地址:https://www.cnblogs.com/DukeLv/p/7995221.html
Copyright © 2011-2022 走看看