删除重复字符

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;  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值