一个字符串中去点重复的字符,同样采用快慢指针。

比如char str[]="abcdacd";-->str="abcd";

思路:

①采用26个字母的映射表

②采用快慢指针进行删除操作

代码:

// getPureStr.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
using namespace std;

void getPureStr(char* str)
{
int a[256]={0};
char* pslow=str,*pfast=str;
while (*pfast!='\0')
{
a[*pfast]++;
if (a[*pfast]==1)//如果只出现一次,那么就要赋值
{
*pslow=*pfast;
pslow++;
}
//如果出现不止一次那么就要删除
pfast++;
}
*pslow='\0';

}


int _tmain(int argc, _TCHAR* argv[])
{
char str[]="abcdadc";

getPureStr(str);
cout< //cout<

system("pause");
return 0;
}

// getPureStr.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
using namespace std;

void getPureStr(char* str)
{
	int a[256]={0};
	char* pslow=str,*pfast=str;
	while (*pfast!='\0')
	{
		a[*pfast]++;
		if (a[*pfast]==1)//如果只出现一次,那么就要赋值
		{
			*pslow=*pfast;
			pslow++;
		}
		//如果出现不止一次那么就要删除
		pfast++;
	}
	*pslow='\0';
	
}


int _tmain(int argc, _TCHAR* argv[])
{
	char str[]="abcdadc";

	getPureStr(str);
	cout<


你可能感兴趣的:(一个字符串中去点重复的字符,同样采用快慢指针。)