repeat——priority_queue 自定义结构体比较

//
#include<bits/stdc++.h>
using namespace std;

struct cmpS
{
    bool operator () ( const int& x,const int& y ) const
    {
        return y < x ;
    }
};
priority_queue< int,vector<int>,cmpS > q;

int main()
{
    int n,x;
    
    while( cin>>n )
    {
        while( !q.empty() ) q.pop();
        
        while( n-- )
        {
            cin>>x; q.push( x );
        }
        while( !q.empty() )
        {
            cout<<q.top()<<" "; q.pop();   
        }
        cout<<endl;
    }
    return 0;
}
// 5 5 4 3 2 1
// 1 2 3 4 5

猜你喜欢

转载自blog.csdn.net/qq_63173957/article/details/124596349