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

来源:互联网 发布:js 图片预览插件 编辑:程序博客网 时间:2024/06/08 11:32

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;}


0 0
原创粉丝点击