HDU 1106
来源:互联网 发布:手机网络动漫城 编辑:程序博客网 时间:2024/05/29 16:12
#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 elem20elem1 equivalent to elem2> 0elem1 greater than elem2The 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.
- hdu 1106
- hdu 1106
- hdu 1106
- hdu 1106
- HDU 1106
- hdu 1106
- hdu 1106
- hdu 1106
- hdu 1106
- hdu 1106
- HDU-1106
- hdu 1106
- HDU 1106
- HDU 1106
- HDU 1106
- HDU 1106
- HDU 1106
- HDU 1106
- 看到3篇文章,不分享出来,简直对不起大家
- occ sample geometry 分析初探2
- 手机订货会新概念
- DRP基础知识总结(二)
- How browsers work--Behind the scenes of modern web browsers
- HDU 1106
- 各浏览器对HTML5的支持情况
- jQuery插件开发中$.extend和$.fn.extend辨析
- 反复平方法求解幂取模问题(java版)
- HttpClient 4.0的使用详解
- S2SH框架搭建常见的问题
- Latex调整表格行距
- 我大学剩下一年半的生活(七)——pythonchallenge之level6
- View animation