Let str be a string that contains any number of lower case letters from this set {a, b, c, .. z}. Samples of some valid str's are aabddd, bttttccd, cafffffgggaat etc. Your program must validate the input (check whether it contains only lowercase letters) and create and print a new string (a copy of str) such that all repeated letters in str are replaced by the number of repeats followed by just one letter, i.e., aa will be replaced by 2a, bbb will be replaced by 3b, etc. Other (non-repeated) letters will remain same, For invalid inputs your program must generate an error message. Some sample strings and the expected outputs are as follows. Sample str = aabddd, expected output = 2ab3d Sample str = bttttccd, expected output = b4t2cd Sample str = caffgggaat, expected output = ca2f3g2at
Let str be a string that contains any number of lower case letters from this set {a, b, c, .. z}. Samples of some valid str's are aabddd, bttttccd, cafffffgggaat etc.
Your
Some sample strings and the expected outputs are as follows.
Sample str = aabddd, expected output = 2ab3d
Sample str = bttttccd, expected output = b4t2cd
Sample str = caffgggaat, expected output = ca2f3g2at
Step by step
Solved in 3 steps with 7 images