#include <iostream>
#include "OJ.h"
using namespace std;
/*
Description
给定一个字符串,将字符串中所有和前面重复多余的字符删除,其余字符保留,输出处理后的字符串。需要保证字符出现的先后顺序。
Prototype
int GetResult(const char *input, char *output)
Input Param
input 输入的字符串
Output Param
output 输出的字符串
Return Value
0 成功
-1 失败及异常
*/
int GetResult(const char *input, char *output)
{
if (NULL == input || NULL == output)
{
return -1;
}
int *ch = new int [256];//做为字符是否已经出现的标记
memset(ch, 0, sizeof(int)*256);
int iInCur =0;
int iOutCur =0;
while ('\0' != input[iInCur])
{
if (0 == ch[input[iInCur]])
{
ch[input[iInCur]] = 1;
output[iOutCur] = input[iInCur];
iOutCur++;
}
iInCur++;
}
output[iOutCur] = '\0';
delete [] ch;
return 0 ;
}
int main()
{
char result[1024] = {0};
GetResult("abadcbad",result);
cout<<result<<endl;
return 0;
}