#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAXCOUNT 2*100 char *transformation(char* str) { int len=strlen(str); char *buf=new char[len+1]; char *p=str; char *q=p+1; int count=1; while(*q) { if(*p==*q) { count++; p++; q++; }else{ itoa(count,buf,10); int nbits=strlen(buf); strcat(buf,q); *q=0; strcat(str,buf); q+=nbits; p=q; q=p+1; count=1; } } itoa(count,buf,10); strcat(str,buf); delete []buf; buf=NULL; return str; } int main() { char str[MAXCOUNT]; printf("please input a string:"); scanf("%s",&str); char *pstr=transformation(str); printf("after transformation:%s ",pstr); return 0; }