HDU 1106

#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 ValueDescription
< 0elem1 less than elem2
0elem1 equivalent to elem2
> 0elem1 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.

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值