using System;
using System.Collections.Generic;
namespace MorseConverter
{
class Program
{
static void Main()
{
Dictionary<String, String> morse = 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"},
{"-----" , "0"},
{".----" , "1"},
{"..---" , "2"},
{"...--" , "3"},
{"....-" , "4"},
{"....." , "5"},
{"-...." , "6"},
{"--..." , "7"},
{"---.." , "8"},
{"----." , "9"}
};
Console.WriteLine("Zadejte text určený pro převod:");
string input = Console.ReadLine();
if (!string.IsNullOrEmpty(input))
{ //rozdělí kody oddělené mezerou nebo lomítkem
string[] words = input.Split(new char[] { ' ', '/' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string word in words)
{
if (morse.TryGetValue(word, out string str)) Console.Write(str);
else Console.WriteLine("Neplatné zadání");
}
}
Console.WriteLine();
Console.WriteLine("Stisknutím libovolné klávesy aplikaci ukončíte...");
Console.ReadKey(false);
Dictionary<char, String> morse = 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' , "----."},
};
Console.WriteLine("Zadejte text určený pro převod:");
string input = Console.ReadLine().ToUpper();
for (int i = 0; i < input.Length; i++)
{
if (i > 0) Console.Write('/');
if (morse.TryGetValue(input[i], out string str)) Console.Write(str);
}
Console.WriteLine();
Console.WriteLine("Stisknutím libovolné klávesy aplikaci ukončíte...");
Console.ReadKey(false);
}
}
}
Inu dobrá, zkusil jsem to "slepit", ale opět mám chyby: https://postimg.cc/0bMv3t4f