#K12451. Encode Morse Code
Encode Morse Code
Encode Morse Code
Given a message consisting of uppercase English letters and spaces, your task is to convert it into Morse code. Each letter is replaced by its corresponding Morse code representation, while spaces in the message are represented by a vertical bar (|
).
The official Morse code for the alphabet is defined as follows:
$$ \begin{array}{cc} A: & .- \\ B: & -... \\ C: & -.-. \\ D: & -.. \\ E: & . \\ F: & ..-. \\ G: & --. \\ H: & .... \\ I: & .. \\ J: & .--- \\ K: & -.- \\ L: & .-.. \\ M: & -- \\ N: & -. \\ O: & --- \\ P: & .--. \\ Q: & --.- \\ R: & .-. \\ S: & ... \\ T: & - \\ U: & ..- \\ V: & ...- \\ W: & .-- \\ X: & -..- \\ Y: & -.-- \\ Z: & --.. \\ \end{array}$$
Example: The message HELLO WORLD
should be encoded as .... . .-.. .-.. --- | .-- --- .-. .-.. -..
.
inputFormat
The input consists of a single line containing the message to be encoded. The message will only contain uppercase English letters and spaces.
outputFormat
Output a single line containing the Morse code representation of the input message. Each letter's code is separated by a space, and spaces in the input are represented by a vertical bar ("|").## sample
HELLO
.... . .-.. .-.. ---