-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (52 loc) · 2.11 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (52 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
namespace morzeCode
{
public class Program
{
public static IDictionary<string, string> MorseCodeDictionary = new Dictionary<string, 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 string morzeDecoder(string morzeMessage)
{
string endMessage = "";
string currentLetter = "";
string[] morseWords = morzeMessage.Split(new[] { " " }, StringSplitOptions.None);
foreach (var mWord in morseWords)
{
foreach (var m in mWord.Split())
{
bool value = MorseCodeDictionary.TryGetValue(m, out currentLetter);
if (value == true)
{
MorseCodeDictionary.TryGetValue(m, out currentLetter);
endMessage += currentLetter;
}
else
{
string currentLetterFalse = "*";
endMessage += currentLetterFalse;
}
}
endMessage += " ";
}
return "Your message: " + endMessage.Trim();
}
public static void Main()
{
Console.WriteLine("Good afternoon! Let's decode your message.");
Console.WriteLine("Enter the morse code and press 'Enter'\n");
string morzeMessage = Console.ReadLine();
string endMessage = (morzeDecoder(morzeMessage));
Console.WriteLine(endMessage);
Console.WriteLine("Click on any button to exit");
Console.ReadKey();
}
}
}