压缩字符串,压缩格式为“字符重复次数+字符”,如:“xxxyyyyz”输出“3x4yz”
void Zip(char str[]){
int i, count = 0;
char ch = str[0];
for(i = 0; i < strlen(str); i++){
if(ch == str[i]){
count++;
}else{
if(count == 1){
printf("%c", ch);
}else{
printf("%d%c", count, ch);
}
ch = str[i];
count = 1;
}
}
if(count == 1){
printf("%c", ch);
}else{
printf("%d%c", count, ch);
}
}