String compression

my code is working fine for the given input but is failing other test cases i cant figure out why
here is my code:https://ide.codingblocks.com/s/249864

you need to solve for local clusters
for example in case aaabbbaaa answer should be a3b3a3, but your answer is a6b3