Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 04. Morse Code Translator
- Write a program that translates messages from Morse code to English (capital letters). Use this page https://morsecode.world/international/morse2.html to help you (without the numbers). The words will be separated by a space (' '). There will be a '|' character which you should replace with ' ' (space).
- Example
- Input Output
- .. | -- .- -.. . | -.-- --- ..- | .-- .-. .. - . | .- | .-.. --- -. --. | -.-. --- -.. . I MADE YOU WRITE A LONG CODE
- .. | .... --- .--. . | -.-- --- ..- | .- .-. . | -. --- - | -- .- -.. I HOPE YOU ARE NOT MAD
- using System;
- public class Program
- {
- public static void Main()
- {
- var morseCode = Console.ReadLine().Split(" | ");
- var capitalLettersMorseCode = new[] {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
- "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
- var translator = "";
- foreach (var words in morseCode)
- {
- var letter = words.Split(" ", StringSplitOptions.RemoveEmptyEntries);
- var counterLetters = 0;
- for (int i = 0; i < letter.Length; i++)
- {
- foreach (var morseSymbols in capitalLettersMorseCode)
- {
- if (letter[i] == morseSymbols)
- {
- if (letter.Length >= i)
- {
- translator += (char)(65 + counterLetters);
- counterLetters = 0;
- }
- if (letter.Length == i + 1)
- {
- translator += ' ';
- break;
- }
- if (letter.Length > i)
- {
- break;
- }
- }
- counterLetters++;
- }
- }
- }
- Console.WriteLine(translator);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement