#C8919. Merge the Tools
Merge the Tools
Merge the Tools
You are given a string s
and an integer k
. Your task is to split the string s
into substrings of size k
(the last substring may be shorter than k
if s
's length is not a multiple of k
). For each substring, remove any duplicate characters while maintaining the order of their first occurrence. Print each resulting substring on a new line.
Note:
- If the character appears multiple times in the substring, only its first occurrence should be kept.
Example:
Input: s = "AABCAAADA", k = 3 Output: AB CA AD</p>Input: s = "AAABBBCCC", k = 3 Output: A B C
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a non-empty string
s
, comprising uppercase letters. - The second line contains an integer
k
, representing the length of each substring to process.
outputFormat
The output should be written to standard output (stdout). For each substring of length k
(or the last substring which might be shorter), print the substring after removing duplicate characters, each on a new line.
AABCAAADA
3
AB
CA
AD
</p>