关于删除字符串中字符的问题
怎么把字符串中重复的字符只保留第一个,数组(或动态存储空间)长度也相应减少,比如aabc 输出abc,aaaaac输出ac
main()
{
char s[]="aaccccbbbddddd";
char c[256]={0};
char *p;
int i=1;
puts(s);
for (p=s; *p; p++)
if (c[(unsigned char)*p] == 0)
c[(unsigned char)*p] = i++;
s[--i] = 0;
for (i=0; i<256; i++)
if (c[i] > 0)
s[c[i]-1] = i;
puts(s);
}
[此贴子已经被作者于2016-12-15 21:59编辑过]