#K5616. Convert String to 2D Array with Padding
Convert String to 2D Array with Padding
Convert String to 2D Array with Padding
You are given an integer t representing the number of test cases. For each test case, you are provided with an integer n and a string s. Your task is to transform the string s into a 2-dimensional array (or grid) where each row has exactly n characters.
If the length of s is not a multiple of n, you must append the character '.' (dot) at the end of the string. Formally, if \(|s| \bmod n \neq 0\), let the number of dots to append be
[ r = n - (|s| \bmod n), ]
so that the new length of the string becomes a multiple of n. Then, split the string into consecutive substrings of length n and output them as rows of the 2D array.
Note: For output formatting, print the rows of each test case on separate lines. If there are multiple test cases, separate the output of consecutive test cases by an empty line.
inputFormat
The input is read from stdin and is structured as follows:
- An integer t representing the number of test cases.
- For each test case:
- An integer n denoting the number of characters per row.
- A string s consisting of only characters (without spaces).
outputFormat
For each test case, output the rows of the 2D array, each on its own line. If there are multiple test cases, insert an empty line between the outputs of consecutive test cases. The output is written to stdout.
## sample2
3
hello
4
example
hel
lo.
exam
ple.
</p>