A telegraph operator must transmit a message one fixed-size block at a time. The outgoing message is a string of lowercase letters. The operator splits it, in order and without overlap, into consecutive blocks that each contain exactly k characters. If the very last block would otherwise contain fewer than k characters, it is padded on the right with a designated filler letter until it reaches exactly length k (earlier blocks always come out full, since only the final block can fall short). The filler letter is guaranteed not to appear anywhere in the original message, so padded characters are always distinguishable from real message characters.
Given the message, the block size k, and the filler letter, output the resulting blocks in order.
Line 1: the message s, a non-empty string of lowercase English letters. Line 2: a single integer k, the block size. Line 3: a single lowercase English letter, the filler character (guaranteed not to occur in s).
Print each block on its own line, in the order they occur in the message.
Example 1
Input
morningstar 4 x
Expected
morn ings tarx
Explanation
The 11-letter message splits into blocks of 4: 'morn', 'ings', and 'tar' (only 3 letters left). Since the last block is short by 1 character, it is padded with 'x' to become 'tarx'.
Example 2
Input
ab 1 z
Expected
a b
Explanation
With block size 1, the 2-letter message splits evenly into 'a' and 'b'; no block is short, so no padding with 'z' is needed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →