Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MorseCodeChallenge
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- public class MorseCodeChallenge
- {
- private const int SleepInterval = 750;
- private const int LongBeepDuration = 1200;
- private const int ShortBeepDuration = 600;
- private const int BeepFrequency = 1200;
- private static readonly Dictionary<char, string> MorseCodes = 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', "--.."},
- {' ', "/"}
- };
- public static void Main()
- {
- string message = Console.ReadLine().ToUpper();
- foreach (var symbol in message.Where(symbol => MorseCodes.ContainsKey(symbol)))
- {
- PlaySound(symbol);
- }
- }
- private static void PlaySound(char symbol)
- {
- foreach (var sound in MorseCodes[symbol])
- {
- switch (sound)
- {
- case '-':
- Console.Beep(BeepFrequency, LongBeepDuration);
- break;
- case '.':
- Console.Beep(BeepFrequency, ShortBeepDuration);
- break;
- case '/':
- Thread.Sleep(SleepInterval);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement