1.2015 华为
(1):

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
int cmp(const void *a, const void *b)
{
return *(int*)a - *(int*)b;
}
int main()
{
char strIn[4096] = {‘\0‘};
char strTemp[4096] = {‘\0‘};
int numResult[4096] = { 0 };
int sizeIn;
int resultCount = 0; //结果数组索引
static int count = 0; //连续的数字计数
while( gets(strIn) != NULL)
{
sizeIn = strlen(strIn); //取得输入的字符串的大小,包括最后的结束符
if(sizeIn != 0)
{
//取得整形数组
for(int i =0; i < sizeIn;)
{
//取得整数
if(strIn[i] >= ‘0‘ && strIn[i] <= ‘9‘)
{
strTemp[count] = strIn[i];
count++;
}
else //遇到非数字
{
if(count != 0) //如果有数字,则取出来
{
//将得到的字符串转换成整形
numResult[resultCount++] = atoi(strTemp);
memset(strTemp, 0, 4096);
count = 0;
}
}
i++;
}
if(count != 0) //取得最后的整数
{
numResult[resultCount++] = atoi(strTemp);
count = 0;
}
qsort(numResult, resultCount, sizeof(int), cmp);
for(int i = 0; i < resultCount - 1; i++)
{
printf("%d ", numResult[i]);
}
printf("%d", numResult[resultCount - 1]); //打印最后一个元素
printf("\n");
resultCount = 0;
count = 0;
memset(strIn, 0, 4096);
memset(strTemp, 0, 4096);
memset(numResult, 0, 4096);
}
}
}
附:快速排序使用方法
C标准库快速排序:http://blog.csdn.net/masibuaa/article/details/5633498
C++快速排序:http://blog.csdn.net/zzzmmmkkk/article/details/4266888
原文:http://www.cnblogs.com/mrethan/p/4611690.html