The problem I faced with this idea was when I was supposed to count the length of some string.
If I get aaa...a (a times 10), this string compressor makes it into "10a".
If I get 'a' * 100, I would get "100a" and so on.
Instead of creating string "100a", I counted the length 4 by using the code under, but I wonder if there's better way to implement this because running switch for every time I increment the count seems redundant and ineffective.
1 2 3 4 5 6 7
count += 1;
switch (count)
{
case 2: cur_length++; break;
case 10: cur_length++; break;
case 100: cur_length++; break;
}
@jonnin
Wow, this was something I've couldn't thought of before. Thank you.
@salem c
@Mitsuru
My work was supposed to get the string and get the length of the compressed string.
I thought not actually having the compressed string it self might have better performance for I won't be needing the memory allocation.
Haven't thought of using length function of string. Thank you
@JLBorges
My problem was that there character which doesn't get repeated should be in form of itself.
i.e.) 'abcdee' => 'abcd2e'
But, using stringstream was something I haven't thought of because I wasn't even thinking about decoding it!
your idea looks great and I think I got much out from it. Thank you.