#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define N 2000
using namespace std;
__int64 heap[N];
char str[2000];
char str1[1010];
char Map[1010][1100];
int print_in(__int64 a)
{
if(heap[0]==N)
return -1;
heap[++heap[0]]=a;
int x=heap[0];
int p=x/2;
while(p>0&&heap[p]>heap[x])
{
swap(heap[p],heap[x]);
x=p;
p=p/2;
}
return 0;
}
int print_out()
{
if(heap[0]==0)
return -1;
__int64 ret=heap[1];
swap(heap[1],heap[heap[0]]);
heap[0]--;
int p=1,x;
int lc,rc;
while(1)
{
lc=p<<1;
rc=p<<1|1;
x=p;
if(lc<=heap[0]&&heap[lc]<heap[x])
x=lc;
if(rc<=heap[0]&&heap[rc]<heap[x])
x=rc;
if(x==p)
break;
swap(heap[x],heap[p]);
p=x;
}
return ret;
}
int main()
{
__int64 a;
while(~scanf("%s",str))
{
heap[0]=0;
int j=0,k=0;
int len=strlen(str);
for(int i=0; i<len; i++)
{
if(str[i]=='5')
{
if(j!=0)
{
str1[j]='\0';
strcpy(Map[k++],str1);
j=0;
}
}
else if(str[i]!='5')
{
str1[j++]=str[i];
}
}
if(str[len-1]!='5')
{
str1[j]='\0';
strcpy(Map[k++],str1);
}
for(int i=0; i<k; i++)
{
a=0;
for(int j=0; j<strlen(Map[i]); j++)
{
a=a*10+Map[i][j]-'0';
}
print_in(a);
}
while(heap[0]>0)
{
cout<<print_out();
putchar(heap[0]!=0?' ':'\n');
}
}
return 0;
}
hdu1106 排序 堆排序
最新推荐文章于 2023-04-21 17:35:23 发布