0
Contracting string in C++
guys i want to contract a string. for example contract hhPwwwttttn into h2Pw3t4n. please help me, its so important for me.
1 Answer
+ 3
char a[100];
cin>>a;
char b[100]; int j=0;
for(int i=0;i<a.length;i++)
{ int ctr=0;
while(a[i]==a[i-1])
{ i++;
ctr++;
}
b[j++]=a[i];
if(ctr>1)
b[j++]=char(ctr+1);
}
remember this code will work if repetetions are less than 10.
however u can optimise program