i try the things and execute it but there is some problem in my code pls take a look the mistake is it do the work for all s[i] and print it in my code
suppose
if string is
abbbacc
then what is the output in this case
or the question is about consecutive repeat of characters
String compression problem doubt
Hey @dipeshgupta197 your coding was having some mistakes in it
1.) the count should be equal to 1 inside the for loop as atleast one char is present in a string
2.) no need of the second for loop just use a simple while loop and apply the conditions in it
https://ide.codingblocks.com/s/627646 here is your corrected code.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
i dry run the same code but not getting what i want
for the first case its fine. the outerloop is run for each character present in the string then after first first a when i=1 for outer loop we have a s[i]==s[i+1] true ans i<length-1 then while loop terminates when i=2 as s[i] !=s[i+1] this is the doubt in this code
No No the while loop will terminate when run till i is less then string length but it will come out of the one if s[i]!=s[i+1]
and increment the count and again run for i = 3 because of the for loop
sir is i said jabb hum while se bahar aajaege too i=1 keliye start hooga na dobara sabkuch too second charachter bhi a hein uss case mein kya hogga
means i=0 ke while chala a3 print kiya sahi hein
phir i=1 hua for loop mein i=1 prr s[1]=a and s[1+1]=a
while(1<length and s[1]==s[2])
i++;
count++ // i=2 and count =2 fer s[2]!=s[3] bahar aajaega
cout<<s[2]<<count // a2 print nhi hogga a3 ke baad
arey bahiya while loop k andar condition bhi to ha count++ and i++ to yha sa bhar jb hi ayaga if
s[i]!=s[i+1] or i becomes greater than length
jb while sa bhar aayaga to i ki value increment hoka i = 3 hogi
fir for loop i = 3 sa start hoga jha count = 1 hoga
Means for I=1 ke baad i=3 keliye forloop run hooga
i = 0 k baad i = 2 sa start hoga