Pagini recente » Cod sursa (job #1619781) | Cod sursa (job #1259253) | Cod sursa (job #472379) | Cod sursa (job #2287602) | Cod sursa (job #710717)
Cod sursa(job #710717)
#include <stdio.h>
#include <vector>
#include <algorithm>
std::vector<int> v;
char c[5500000],*p;
bool cmp(int a,int b){if(a>b)return true; else return false;}
int number(char*&p){
int x=0;
while('0'<=*p&&*p<='9'){
x=x*10+*p-'0'; p++;}
while(*p==' ')p++;
return x;
}
int main(){
int n,i,x;
freopen("algsort.in","r",stdin);
freopen("algsort.out","w",stdout);
scanf("%d ",&n);
fgets(c,5500000,stdin);
p=c;
for(i=0;i<n;i++){
x=number(p);
v.push_back(x);
push_heap(v.begin(),v.end(),cmp); }
for(i=0;i<n;i++){
printf("%d ",v[0]);
pop_heap(v.begin(),v.end(),cmp);
v.pop_back();}
}