#C12730. Encode Consecutive Characters
Encode Consecutive Characters
Encode Consecutive Characters
You are given a string s
. Your task is to encode the string such that each character is immediately followed by the number of times it appears consecutively. For example, if the input is aaabbcaaa
, the output should be a3b2c1a3
.
Note: The input will be provided as a single line from standard input and the output should be printed to standard output. If the input string is empty, print an empty line.
Examples:
- Input:
aaabbcaaa
→ Output:a3b2c1a3
- Input:
abc
→ Output:a1b1c1
- Input:
AAAA
→ Output:A4
inputFormat
The input consists of a single line containing the string s
that you need to encode.
Input Format: A single line of text.
outputFormat
Output the encoded string where each character is immediately followed by its count of consecutive occurrences.
Output Format: A single line of text representing the encoded string.
## sampleaaabbcaaa
a3b2c1a3