[BAEKJOON] 백준 9289: Morse Code (C#)

2024. 8. 22. 14:46IT/BaekJoon

문제 링크

https://www.acmicpc.net/problem/9289

 

 

문제

Morse code was an early method of communication via electronic signals. Each letter and number was represented by a unique series of long and short tones, with a pause to indicate the beginning of the next character. Implement a Morse Code interpreter, using the key to the right, that translates five-letter messages (no more, no less).

 

 

입력

The first line of input is the number of test cases that follow.

Each input case appears on a single line, and will include five Morse code characters, a space-separated series of long and short tones, represented by dots and dashes.

There will be at most 1000 test cases.

 

 

출력

For each case, output the line “Case x:” where x is the case number, on a single line. Then output a single space followed by an all-caps alphanumeric representation of the message, exactly five characters in length.

 

 

 

통과한 답안

namespace _9289
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] inputs = Console.ReadLine().Split(' ');
                string text = "";
                for (int j = 0; j < inputs.Length; j++)
                {
                    text += MorseText(inputs[j]);
                }
                Console.WriteLine($"Case {i + 1}: {text}");
            }
        }

        static string MorseText(string text)
        {
            switch (text)
            {
                case ".-": return "A";
                case "-...": return "B";
                case "-.-.": return "C";
                case "-..": return "D";
                case ".": return "E";
                case "..-.": return "F";
                case "--.": return "G";
                case "....": return "H";
                case "..": return "I";
                case ".---": return "J";
                case "-.-": return "K";
                case ".-..": return "L";
                case "--": return "M";
                case "-.": return "N";
                case "---": return "O";
                case ".--.": return "P";
                case "--.-": return "Q";
                case ".-.": return "R";
                case "...": return "S";
                case "-": return "T";
                case "..-": return "U";
                case "...-": return "V";
                case ".--": return "W";
                case "-..-": return "X";
                case "-.--": return "Y";
                case "--..": return "Z";
                default:
                    return "";
            }
        }
    }
}

 

주어진 모스부호를 해독하는 문제이다.

각각의 모스부호를 해독하기 위해서 switch 문을 이용하여 구현하였다.