Chinaunix首页 | 论坛 | 博客
  • 博客访问: 718339
  • 博文数量: 161
  • 博客积分: 2998
  • 博客等级: 少校
  • 技术积分: 1697
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-28 09:39
文章分类

全部博文(161)

文章存档

2012年(6)

2011年(120)

2010年(35)

分类: WINDOWS

2012-08-26 00:40:17

#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) |
0

上一篇:记录

下一篇:VC XML 操作

给主人留下些什么吧!~~