using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MorseConverter
{
class Program
{
static void Main(string[] args)
{
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' , "----."},
};
Dictionary<String, String> morse1 = 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();
input = input.ToUpper();
for (int i = 0; i < input.Length; i++)
{
if (i > 0)
Console.Write('/');
char c = input[i];
if (morse.ContainsKey(c))
Console.Write(morse[c]);
}
for (int i = 0; i < input.Length; i++)
{
if (i > 0)
Console.Write('/');
string c = input[i];
if (morse1.ContainsKey(c))
Console.Write(morse1[c]);
}
Console.WriteLine();
Console.WriteLine("Stisknutím libovolné klávesy aplikaci ukončíte...");
Console.ReadKey(false);
}
}
}
Zdravím, mám tento kód, je to převod textu na Morse i obráceně.
Vše funguje, jen ten řádek "string c = input[i];" pořád hlásí error - Typ char nejde implicitně převést na typ string - jak to poladit, aby program fungoval tak, jak si představuju...?