#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int find_transtoint(char *pinput, int *ptranto)
{
char *ptmp = pinput;
char autmp[256] = {0};
int i = 0;
while(*pinput != '\0')
{
if(*pinput == ' ')
{
memcpy(autmp, ptmp, pinput-ptmp);
ptranto[i] = atoi(autmp);
i++;
ptmp = pinput+1;
}
pinput++;
}
ptranto[i] = atoi(ptmp);
/* 返回实际的个数 */
return (i+1);
}
void find_swap(int *pswapto, int ilen)
{
int iMin = 0;
int i = 0;
int j = 1;
int iRecord = 0;
int iTmp = 0;
if(1 == ilen)
{
return;
}
while(i < ilen)
{
iMin = (pswapto[i]%1000);
j = i+1;
while(j < ilen)
{
if(iMin > (pswapto[j]%1000))
{
iMin = pswapto[j]%1000;
iRecord = j;
}
j++;
}
iTmp = pswapto[iRecord];
pswapto[iRecord] = pswapto[i];
pswapto[i] = iTmp;
i++;
}
}
void find_string(char *pinput, char *output)
{
int iaInput[256] = {0};
char caInput[256] = {0};
int iLen = 0;
int i = 0;
if((pinput == NULL)||(*pinput == '\0'))
{
return;
}
iLen = find_transtoint(pinput, iaInput);
find_swap(iaInput, iLen);
while(i < iLen)
{
memset(caInput, 0, sizeof(caInput));
ltoa(iaInput[i], caInput, 10);
if(i == 0)
{
sprintf(output, "%s", caInput);
}
else
{
sprintf(output, "%s %s", output, caInput);
}
i++;
}
}
int main()
{
//char *p = "123 1000 2000 3380 4670 5822 5022";
char *p = "";
char acoutput[1024] = {0};
find_string(p, acoutput);
return 0;
}
阅读(2259) | 评论(0) | 转发(0) |