morseovkausing System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp1{ class Program { static void Main(string[] args) { String a, b; Dictionary<char, String> morse = new Dictionary<char, String>() // knihovna pro do morseovky { {'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' , "--.."}, }; Dictionary<String, char> morse2 = new Dictionary<String, char>() // knihovna pro z morseovky { { ".-" , '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'}, }; char c; do { Console.WriteLine("_______________________"); // MENU Console.WriteLine("Překladač Morseovky"); // MENU Console.WriteLine("________________________"); // MENU Console.WriteLine("Z hůlkového písma do Morseovky [m]");// MENU Console.WriteLine("Z Morseovky do hůlkového [h]"); // MENU Console.WriteLine("Zadat slova do souboru [s]"); // MENU Console.WriteLine("Konec [k]"); c = char.ToLower(Console.ReadKey().KeyChar); Console.Clear(); switch (c) { case 's': //pokud se stiskne 's' jde to sem Console.WriteLine("v hůlkovém [h]"); Console.WriteLine("v morseovce [m]"); ConsoleKeyInfo keyinfo; keyinfo = Console.ReadKey(true); if (keyinfo.Key == ConsoleKey.H) //pokud se stiskne 'h' jde to sem { Console.Clear(); Console.WriteLine("Zadejte slovo k přeložení"); a = Console.ReadLine(); using (StreamWriter sw = new StreamWriter(@"soubor.txt")) //zalozeni souboru soubor.txt { sw.WriteLine(a); // a > souboru sw.Flush(); } Console.Clear(); } else { if (keyinfo.Key == ConsoleKey.M) { Console.Clear(); Console.WriteLine("Zadejte slovo k přeložení (písmena oddělujte mezerou)"); a = Console.ReadLine(); using (StreamWriter sw = new StreamWriter(@"soubor1.txt")) //zalozeni souboru soubor1.txt { sw.WriteLine(a); // a > souboru sw.Flush(); } Console.Clear(); } } break; case 'm': //pokud se stiskne 'm' jde to sem Console.WriteLine("Zadat ručně [r]"); Console.WriteLine("Zadat ze souboru [s]"); keyinfo = Console.ReadKey(true); if (keyinfo.Key == ConsoleKey.R) //pokud se stiskne 'r' jde to sem { Console.Clear(); Console.WriteLine("Zadejte slovo k přeložení"); a = Console.ReadLine(); a = a.ToUpper(); // převede na velká písmena for (int i = 0; i < a.Length; i++) // a.length ziska pocet znaku v a { if (i > 0) Console.Write('/'); char q = a[i]; if (morse.ContainsKey(q)) //urcuje zda je v knihovne Console.Write(morse[q]); } } else { if (keyinfo.Key == ConsoleKey.S) //pokud se stiskne 's' jde to sem { Console.Clear(); using (StreamReader sr = new StreamReader(@"soubor.txt")) // bere se ze souboru soubor.txt { string slovo; while (!(sr.EndOfStream)) { slovo = sr.ReadLine(); slovo = slovo.ToUpper(); for (int i = 0; i < slovo.Length; i++) { if (i > 0) Console.Write('/'); char q = slovo[i]; if (morse.ContainsKey(q)) Console.Write(morse[q]); } } } } } Console.ReadKey(); Console.Clear(); break; case 'h': //pokud se stiskne 'h' jde to sem Console.WriteLine("Zadat ručně [r]"); Console.WriteLine("Zadat ze souboru [s]"); keyinfo = Console.ReadKey(true); if (keyinfo.Key == ConsoleKey.R) { Console.Clear(); Console.WriteLine("Zadejte slovo k přeložení (písmena oddělujte mezerou)"); String[] pole; b = (Console.ReadLine()); pole = b.Split(' '); // rozdeleni podle mezer for (int i = 0; i < pole.Length; i++) { Console.Write(morse2[pole[i]]); } } else { if (keyinfo.Key == ConsoleKey.S) { Console.Clear(); using (StreamReader sr = new StreamReader(@"soubor1.txt")) // bere se ze souboru soubor1.txt { string slovo; while (!(sr.EndOfStream)) { string[] pole; slovo = sr.ReadLine(); pole = slovo.Split(' '); for (int i = 0; i < pole.Length; i++) { Console.Write(morse2[pole[i]]); } } } } } Console.ReadKey(); Console.Clear(); break; default: break; } } while (c != 'k'); Console.WriteLine("KONEC PROGRAMU"); Console.ReadKey(false); } }} Ukázat celý příspěvek