题目地址 : http://acm.hdu.edu.cn/showproblem.php?pid=1106很简单的一道水题, 就是直接字符串拆分就行了,好好学习了一下C++的字符串分割函数 #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp ( const void *p, const void *t ) { return *(int *)p - *(int *)t; } char s[1010]; int a[1010]; int main() { while ( scanf("%s",s) != EOF ) { char *t; int n = 1; memset ( a, 0, sizeof ( a ) ); t = strtok ( s,"5" ); a[0] = atoi ( t ); while ( t = strtok ( NULL,"5" ) ) { a[ n ++ ] = atoi ( t ); } qsort ( a, n, sizeof ( int ), cmp ); for ( int i = 0; i != n; ++ i ) { printf(i ? " %d" : "%d",a[i]); } putchar ( '/n' ); } return 0; }