#include<stdio.h>
#include<algorithm>
using namespace std;
    bool cmp(int x,int y)//定义比较函数,为真时,大的排在小的前边
    {
        return x>y;
    }
int main()
{
    int n;
    int buff[10000];

    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&buff[i]);
        }
        sort(buff,buff+n,cmp);//加入比较函数,sort使用方法sort(排序起始地址,排序终止地址,比较函数)
        for(i=0;i<n;i++)
            printf("%d ",buff[i]);
    }
    printf("\n");
    return 0;
}



/*functional提供了一堆基于模板的比较函数对象,它们是(看名字就知道意思了):equal_to<Type>、
not_equal_to<Type>、greater<Type>、greater_equal<Type>、less<Type>、less_equal<Type>。*/
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
    /*bool cmp(int x,int y)
    {
        return x>y;
    }*/
int main()
{
    int n;
    int buff[10000];

    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d",&buff[i]);
        }
        sort(buff,buff+n,less<int>());//升序,降序的话用greater<int>
        for(i=0;i<n;i++)
            printf("%d ",buff[i]);
    }
    printf("\n");
    return 0;
}

 

 

 

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2021-06-21
  • 2021-07-28
  • 2021-09-23
  • 2021-07-29
  • 2021-11-25
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2021-07-29
  • 2022-12-23
  • 2021-05-16
  • 2021-11-19
  • 2021-11-14
相关资源
相似解决方案