首页 > 代码库 > 去除连续字符

去除连续字符

//描述:输入一串字符(包括数字),去掉连续次数多于3的字符,如果去掉后仍有连续次数多于3的,//继续进行同样的处理,直到结果中没有出现连续次数多于3的数字为止。#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <string.h>int flag = 0;void delete(char s[]){	int length;	int i, j, k , m;	length = strlen(s);	flag = 0;	for (i = 2; i < length; )	{		if ((s[i] == s[i - 1]) && (s[i] == s[i - 2]))		{			j = i - 2;			do			{				i++;			} while (s[i] == s[i - 1]);			for (k = i; k <= length; k++)			{				s[k - (i - j)] = s[k];			}			m = i;			length -= (m - j);			i -= (m - j);			flag = 1;			//i += 2;		}		else		{			i++;		}	}}int main(){	char s[255];	gets(s);	do	{		delete(s);	} while (flag == 1);	if (s[0] == ‘\0‘)		printf("%s", "NONE");	else		printf("%s", s);	return 0;}