#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp(const void*a,const void*b)
{
return *(int *)a-*(int *)b;
}
int main()
{
char number[1001];
while(scanf("%s",number)!=EOF)
{
int i,len,k=0,flag=0;
int num[1001];
memset(num,0,sizeof(int)*1001);
len=strlen(number);
for(i=0;i<len;)
{
if(number[i]=='5')
{
i++;
}
while(number[i]!='5'&&i<len)
{
num[k]=num[k]*10+number[i]-48;
i++;
flag=1;
}
if(flag==1)
{
k++;
flag=0;
}
}
qsort(num,k,sizeof(int),cmp);
for(i=0;i<k-1;i++)
{
printf("%d ",num[i]);
}
printf("%d\n",num[k-1]);
}
return 0;
}
The qsort function implements a quick-sort algorithm to sort an array ofnum elements, each ofwidth bytes. The argumentbase is a pointer to the base of the array to be sorted.qsort overwrites this array with the sorted elements. The argumentcompare is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship.qsort calls thecompare routine one or more times during the sort, passing pointers to two array elements on each call:
compare( (void *) elem1, (void *)elem2);
The routine must compare the elements, then return one of the following values:
Return Value | Description |
< 0 | elem1 less than elem2 |
0 | elem1 equivalent to elem2 |
> 0 | elem1 greater than elem2 |
The array is sorted in increasing order, as defined by the comparison function. To sort an array in decreasing order, reverse the sense of “greater than” and “less than” in the comparison function.