題目描述:“eeeeeaaaff" 壓縮爲 "e5a3f2",請編程實現。
void compress(char *s)
{
char *p = s, *q = s;
char t;
while(*p)
{
t = *p;
*q++ = t;
int nCnt = 1;
while(*p && *(++p)==t) nCnt++;
if(nCnt>1)
{
q += sprintf(q, "%d", nCnt);
}
}
}