-
What’s wrong with this? Are non-continuous same characters considered as one?
like aabbbaaabc => a5b4c1 ? -
Also how do I type cast string to different data type? Is it possible without stringstream ?
-
Why is this wrong? both out and inp are strings of string class. out[j] = in[i];
i have used out += in[i]. why is it not possible to assign a single char like out[j] = in[i] ?
String Compression
- output of “aabbbaaabc” would be “a2b3a3b1c1”. You are doing it correctly in your code.
- You can create a small function to change integer to string. But stringstream work well here.
- your code is giving wrong output for such testcases “aaaaaaaaaa”. output should be “a10” but your code is printing “a1”. Just comment out line no. 7. your code will work fine. You don’t need to out[j]=’\0’; since it’s already zero.
Okay yeah I get it, it doesn’t work for double or more digit numbers.
But are strings terminated with a null character by default?
Are strings terminated by a null character by default?
1 Like
@alien
i think you got the logic and successfully submitted it. So please mark it as resolved. thnaks
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.