嗯,这道题没什么难度,一次AC。但是发现了一种别人的另类解法,下面贴代码:

/* HDU1106 排序(解法二) */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int cmp(const void *a,const void *b)
{
    return *(int*)a - *(int*)b;
}
 
int main(void)
{
    char s[1024];
    int values[1024], count, i;
    char delim[] = "5";
    char *p;
 
    while(gets(s) != NULL) {
        count = 0;
 
        p = strtok(s, delim);
        while(p) {
             values[count++] = atoi(p);
 
             p = strtok(NULL, delim);
        }
 
        if(count > 0) {
            qsort(values, count, sizeof(values[0]), cmp);
 
            for(i=0; i<count-1; i++)
                printf("%d ", values[i]);
            printf("%d\n", values[count-1]);
        }
    }
 
    return 0;
}

里面用到几个陌生(应该是我太菜的原因)的函数,要先搞懂。

strtok函数(分割字符串用)  atoi函数(将字符转换成整型)

下面分析一下思路:

  首先,读入一个字符串后,用strtok函数把  字符串 分割成 一个个  子字符串,然后用 atoi函数 把每个子字符串 转换成 整数 存入数组,最后用  快排  排下序 就能输出了。