#include <stdio.h>
#include <string.h>
#include <memory.h>
/*
* @brief str_process 将输入的字符串中重复的部分剔除,并且排序输出
* @param src_str 输入的源字符串
* @param dest_str 处理后输出字符串
* @return 成功:0;失败: -1。
*/
int process_str(char *src_str, char* dest_str)
{
int i = 0;
int j = 0;
char temp;
int str_len = 0;
int min = 0;
/*第一步:对输入源字符串进行从小到大的排序,第一是冒泡排序,第二是选择排序*/
str_len = strlen(src_str);
printf("str_len:%d\n",str_len);
#if 0
for(i = 0; i < str_len - 1; i++)
{
for(j = 0; j < str_len - 1- i; j++)
{
if(src_str[j] > src_str[j + 1])
{
temp = src_str[j];
src_str[j] = src_str[j + 1];
src_str[j + 1] = temp;
}
}
}
#endif
for(i = 0; i < str_len; i++)
{
min = i;
for(j = i+1; j < str_len; j++ )
{
if(src_str[min] > src_str[j])
{
min = j;
}
}
if(min != i)
{
temp = src_str[min];
src_str[min] = src_str[i];
src_str[i] = temp;
}
}
printf("now we check src_str:%s\n",src_str);
/*第二步:去掉相同的字符*/
for(i = 0,j = 0; i < str_len; i++)
{
if(src_str[i] != src_str[i + 1])
{
dest_str[j++] = src_str[i];
}
}
printf("now we check dest_str:%s\n",dest_str);
return 0;
}
int main(void)
{
char test_src_str[100];
char test_dest_str[100];
memset(test_dest_str,0,100);
gets(test_src_str);
process_str(test_src_str, test_dest_str);
getch();
return 0;
}