C#C
C#3y ago
احمد

✅ Morse Code Decoder

using System.Collections.Generic;


class MorseCodeDecoder
{
    public static string Decode(string morseCode)
    {

        string[] morse_code_holder = morseCode.Split(' ');

        Dictionary<char, string> _morseCode = new Dictionary<char, string>()
        {
        {'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', "--.."},
        {'0', "-----"},
        {'1', ".----"},
        {'2', "..---"},
        {'3', "...--"},
        {'4', "....-"},
        {'5', "....."},
        {'6', "-...."},
        {'7', "--..."},
        {'8', "---.."},
        {'9', "----."},
        {'.', ".-.-.-"},
        {',', "--..--"},
        {'?', "..--.."},
        {'\'', ".----."},
        {'!', "-.-.--"},
        {'/', "-..-."},
        {'(', "-.--."},
        {')', "-.--.-"},
        {'&', ".-..."},
        {':', "---..."},
        {';', "-.-.-."},
        {'=', "-...-"},
        {'+', ".-.-."},
        {'-', "-....-"},
        {'_', "..--.-"},
        {'\"', ".-..-."},
        {'$', "...-..-"},
        {'@', ".--.-."},
        {' ', "/"}
        };

        foreach ( var kvp in _morseCode )
        {
            char kvpk = kvp.Key;
            int i = 0;

            if (morse_code_holder[i].Contains(kvpk))
            {
                morse_code_holder[i] = kvp.Value;
            }
        }

        string sumOfMorseCode = string.Join(" ", morse_code_holder);

        Console.WriteLine(sumOfMorseCode);

        throw new System.NotImplementedException("Please provide some code.");
    }
}
Was this page helpful?