// 输出一个字符串中没有重复的字符.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "string.h"
//1 输出一个字符串中没有重复的字符。如“baaca”输出“bac”。
void trimMultipleCharacter(char *array)
{
char table[256] = {0};
int size = strlen(array);
for (int i=0; i<size; i++)
{
table[array[i]]++;
}
char *pCopy, *pCur;
pCopy = pCur = &array[0];
while(*pCur != '\0')
{
if (table[*pCur] > 0)
{
table[*pCur] = 0;
*pCopy++ = *pCur++;
}
else
{
pCur++;
}
}
*pCopy = '\0';
}
int _tmain(int argc, _TCHAR* argv[])
{
char Array[] = {"aadbccddecffegdabghkiikkkk"};
trimMultipleCharacter(Array);
printf("%s", Array);
return 0;
}
输出一个字符串中没有重复的字符。如“baaca”输出“bac”
最新推荐文章于 2022-03-25 20:10:03 发布