删除重复元素 蓝桥杯 C语言

/*
为库设计新函数DelPack,删除输入字符串中所有的重复元素。不连续的重复元素也要删除。
  要求写成函数,函数内部使用指针操作。
样例输入
1223445667889
样例输出
13579
样例输入
else
样例输出
ls
数据规模和约定
  字符串数组最大长度为100。
*/
#if 1
#include <stdio.h>


void sc_cf(char *);
int you_xt(char,char *);
void sc(char,char *);


int main(void)
{
char str[100+1];
gets(str);
sc_cf(str);
puts(str);
return 0;
}


void sc(char c,char * s)
{
char * x = s;
do
{
if( * s != c )
{
* x ++ = * s ;
}
}
while( * s ++ != '\0');
}


int you_xt(char c,char * s)
{
while( * s != '\0' )
{
if( * s == c )
{
return 1;
}
s ++ ;
}
return 0;
}


void sc_cf(char * s)
{
while( * s != '\0' )
{
if( you_xt(* s,s + 1) )
{
sc(* s,s);
sc_cf(s + 1);
}
else
{
sc_cf(s + 1);
}
s ++;
}
}
#endif 

猜你喜欢

转载自blog.csdn.net/qq_40990854/article/details/80148848
今日推荐