#B2123. P-Type Encoding
P-Type Encoding
P-Type Encoding
Given a string str
composed entirely of digit characters ('0'-'9'), compute its p-type encoding string. The p-type encoding is defined by replacing each maximal contiguous group of identical digits by a two-part string: the count of digits in the group (in decimal) followed by the digit itself.
For example:
- The string
122344111
is composed of the groups: "1", "22", "3", "44", "111". It is thus described as "1个1, 2个2, 1个3, 2个4, 3个1" and its p-type encoding is1122132431
. - The string
1111111111
(ten 1's) is described as "10个1" and its p-type encoding is101
(i.e., \(10\) followed by 1 written as "101"). - The string
00000000000
(eleven 0's) is described as "11个0", hence its encoding is110
. - The string
100200300
breaks into groups: "1", "00", "2", "00", "3", "00" which are described as "1个1, 2个0, 1个2, 2个0, 1个3, 2个0"; the resulting encoding is112012201320
.
Your task is to implement a program that, given such a string, outputs its p-type encoding.
inputFormat
The input is a single line containing the string str
composed solely of digits ('0'-'9').
outputFormat
Output a single line containing the p-type encoding of the input string.
sample
122344111
1122132431