Compress the String

3.5

2 votes
Easy
Problem

 

Write a program to do basic string compression. For a character which is consecutively repeated more than once, replace consecutive duplicate occurrences with the count of repetitions.
For e.g. if a String has 'x' repeated 5 times, replace this "xxxxx" with "x5".
Note : Consecutive count of every character in input string is less than equal to 9.
Input Format :

Input string S

Output Format :

Compressed string

Sample Input:

aaabbccdsa

Sample Output:

a3b2c2dsa

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?