Compare commits
2
Commits
ddb515f3e5
...
aa35d4a0f9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa35d4a0f9
|
||
|
|
f53c47684a
|
+45
-3
@@ -8,6 +8,8 @@
|
||||
/// └─────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks.Dataflow;
|
||||
|
||||
class PI114
|
||||
{
|
||||
@@ -48,9 +50,10 @@ class PI114
|
||||
{
|
||||
Console.WriteLine($"Key: {ele.Key}, Value: {ele.Value}");
|
||||
}
|
||||
askUserSentence();
|
||||
IDictionary<string, string> letterToMorse = programmeLetterToMorseCode();
|
||||
askUserSentence(letterToMorse);
|
||||
}
|
||||
static void programmeLetterToMorseCode()
|
||||
public static IDictionary<string,string> programmeLetterToMorseCode()
|
||||
{
|
||||
Dictionary<string, string> letterToMorse = new Dictionary<string, string>();
|
||||
letterToMorse.Add("a", ".-");
|
||||
@@ -89,12 +92,51 @@ class PI114
|
||||
letterToMorse.Add("8", "---..");
|
||||
letterToMorse.Add("9", "----.");
|
||||
letterToMorse.Add(" ", "/");
|
||||
return letterToMorse;
|
||||
}
|
||||
static void askUserSentence()
|
||||
static void askUserSentence(IDictionary<string, string> letterToMorse)
|
||||
{
|
||||
Console.Write("Entrez votre phrase à déchiffrer : ");
|
||||
string userText = Console.ReadLine();
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(userText);
|
||||
userTextToAnArray(userText, letterToMorse);
|
||||
}
|
||||
|
||||
static void userTextToAnArray(string userText, IDictionary<string, string> letterToMorse)
|
||||
{
|
||||
string[] userTextArray = userText.Select(x => x.ToString()).ToArray();
|
||||
translateUserSentenceToMorse(userTextArray, letterToMorse);
|
||||
}
|
||||
static void translateUserSentenceToMorse(string[] userTextArray, IDictionary<string, string> letterToMorse)
|
||||
{
|
||||
Console.WriteLine(string.Join(" ", userTextArray));
|
||||
foreach (string k in userTextArray)
|
||||
{
|
||||
foreach(KeyValuePair<string, string> v in letterToMorse)
|
||||
{
|
||||
if (k == v.Key)
|
||||
{
|
||||
if (v.Value.Contains("."))
|
||||
{
|
||||
var resultCount = v.Value.Count(x => x.ToString() == ".");
|
||||
for (int i = 0 ; i < resultCount; i++)
|
||||
{
|
||||
Console.Beep(1000, 200);
|
||||
}
|
||||
}
|
||||
else if (v.Value.Contains("-"))
|
||||
{
|
||||
var resultCount = v.Value.Count(x => x.ToString() == "-");
|
||||
for (int i = 0 ; i < resultCount; i++)
|
||||
{
|
||||
Console.Beep(1000, 200);
|
||||
}
|
||||
}
|
||||
Console.Write(v.Value + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user