#K95422. Sort Messages by Identifier
Sort Messages by Identifier
Sort Messages by Identifier
You are given a number id_length which specifies the fixed number of digits in the identifier of each message. Each message is a string that starts with the character '#' followed by a numeric identifier (of length id_length) and then some text content.
Your task is to sort the messages in ascending order based on the numerical value of their identifier. If two messages have the same identifier, they should remain in their original order (i.e., the sort is stable).
The identifier should be extracted using the formula:
\( id = \text{int}(msg[1:1+id\_length]) \)
inputFormat
The input is read from standard input (stdin) and has the following format:
id_length n message_1 message_2 ... message_n
Where:
id_length
is an integer representing the fixed number of digits in the identifier.n
is the number of messages.- Each
message_i
is a string starting with '#' followed by exactlyid_length
digits and then additional text.
</p>
outputFormat
Output the sorted messages to standard output (stdout), each on a new line, in ascending order based on their numeric identifier.
## sample3
4
#123Hello
#456World
#123Again
#789Compete
#123Hello
#123Again
#456World
#789Compete
</p>