Description
给定一个字符串,将字符串中所有和前面重复多余的字符删除,其余字符保留,输出处理后的字符串。需要保证字符出现的先后顺序。
Prototype
int GetResult(const char *input, char *output)
Input Param
input 输入的字符串
Output Param
output 输出的字符串
Return Value
0 成功
-1 失败及异常
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
int GetResult(const char *, char *);
//char *inCh = "abAdcbad";
char *inCh = "adcdcdcsc";
char OutCh[10] = {0};
int nRst = 0;
nRst = GetResult(inCh, OutCh);
return 0;
}
int GetResult(const char *input, char *output)
{
unsigned int i=0;
unsigned int j=0;
unsigned int cnt=0;
int flag=1;
unsigned int lenIn=0;
unsigned int lenOut=0;
//判断输入和输出有效性
if((input == NULL) || (output == NULL))
{
return -1;
}
lenIn=strlen(input);
for(i = 0; i<lenIn; i++)
{
flag = 1;
for(j = 0; j < lenOut; j++)
{
if(output[j] == input[i])
flag = 0;
}
if(flag)
{
output[cnt++] = input[i];
output[cnt] = '\0';
lenOut = strlen(output);
}
}
output[cnt] = '\0';
return 0;
}