#K70797. Decode the Pyramid Layers
Decode the Pyramid Layers
Decode the Pyramid Layers
You are given a pyramid of symbols encoded in layers. For each test case, an integer N is provided, representing the dimension of each layer in the pyramid in the form of $N \times N$. Following that, there are exactly N*N
lines of input whose concatenation yields a string of symbols. This string is then split into layers, each of length N*N
(i.e. each layer is a chunk of the concatenated string). For every layer, your task is to count the frequency of each distinct symbol and output the results in ascending order of the symbols.
The output for each layer should begin with a line of the form "Layer i:" (where i
is the layer index starting from 0
), followed by multiple lines of the format "symbol:count" indicating the count of that symbol in the respective layer.
Make sure your solution reads from standard input and writes to standard output.
inputFormat
The input is read from stdin and has the following format:
T N line1 line2 ... (N*N lines for the first test case) N line1 line2 ... (N*N lines for the second test case) ...
Where:
T
is the number of test cases.- For each test case, the first line is an integer
N
, and the nextN*N
lines together represent the pyramid symbols (when concatenated) for that test case.
outputFormat
The output should be written to stdout in the following format for each test case:
Layer 0: symbol1:count symbol2:count ... Layer 1: symbol1:count ...
Each frequency line should list the symbol and its count separated by a colon (:
), and the symbols should appear in ascending order based on their ASCII value.
1
2
aabb
cccc
dddd
eeee
Layer 0:
a:2
b:2
Layer 1:
c:4
Layer 2:
d:4
Layer 3:
e:4
</p>