天天看點

pat(A)3-09. 隊列中的元素排序(優先隊列)

1.連結:http://www.patest.cn/contests/ds/3-09

2.代碼:

#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

struct Node
{
    int x;
    bool operator<(Node a)const
    {
        return a.x<x;
    }
};

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        priority_queue<Node> Q;
        while(n--)
        {
            int x;
            scanf("%d",&x);
            Node a;
            a.x=x;
            Q.push(a);
        }
        while(!Q.empty())
        {
            printf("%d",Q.top().x);
            Q.pop();
            break;
        }
        while(!Q.empty())
        {
            printf(" %d",Q.top().x);
            Q.pop();
        }
        printf("\n");
    }
    return 0;
}