[恢]hdu 1106
2011-12-17 01:26:33
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1106
题意:中文。字符串处理,总觉得写的不完满。
代码:
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
char str[1010] ;
int a[1010] ;
int cmp(const void *a, const void *b)
{
return *(int*)a - *(int*)b ;
}
int main ()
{
int cnt = 0, flag = 0, cur ;
int i ;
while (gets (str))
{
str[strlen(str)+1] = '\0' ;
str[strlen(str)] = '5' ;
flag = 0, cur = 0, cnt = 0 ;
for (i = 0 ; str[i] ; i++)
{
if (str[i] != '5')
cur = cur*10 + str[i]-'0',
flag++ ;
else if (flag != 0)
a[cnt++] = cur, flag = cur = 0 ;
}
qsort (a, cnt, 4, cmp) ;
for (i = 0 ; i < cnt ;i ++)
printf (i==0?"%d":" %d", a[i]) ;
printf ("\n") ;
}
return 0;
}