一个字符串“aasbbsdsskkff”,求出重复的次数,并写到数组后面,
输出为“a2s1b2s1d1s2k2f2”
#include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char str[]="aasbbsdsskkff"; char *out=new char [strlen(str)+10]; int i=0,j=0; int count=1; while(str[i]!=' ') { if(str[i]==str[i+1]) { count++; } else { out[j]=str[i]; out[j+1]=count+'0'; count=1; j=j+2; } i++; } out[j]=' '; cout<<out; return 0; }