题解 UVA11462 【Age Sort】

2018-03-29 16:49:18


用优先队列

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

priority_queue <int, vector<int>, greater<int> > q;

int main(){
    ios::sync_with_stdio(false);//优化输入输出
    int n,tmp;
    while(true){
        scanf("%d",&n);
        if(n==0) break;
        for(int i=0;i<n;++i){
            scanf("%d",&tmp);
            q.push(tmp);
        }
        for(int i=0;i<n-1;++i){
            cout<<q.top()<<" ";
            q.pop();
        }
        cout<<q.top()<<endl;
    }
}

博客:aptx.xin