Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Morse code
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static Dictionary<char, string> translator; public static void Main(string[] args) { //Your code goes here InitialiseDictionary(); getUserInput(); Console.WriteLine("Hello, world!"); } private static void InitialiseDictionary() { char dot = '.'; char dash = '−'; translator = new Dictionary<char, string>() { {'a', string.Concat(dot, dash)}, {'b', string.Concat(dash, dot, dot, dot)}, {'c', string.Concat(dash, dot, dash, dot)}, {'d', string.Concat(dash, dot, dot)}, {'e', dot.ToString()}, {'f', string.Concat(dot, dot, dash, dot)}, {'g', string.Concat(dash, dash, dot)}, {'h', string.Concat(dot, dot, dot, dot)}, {'i', string.Concat(dot, dot)}, {'j', string.Concat(dot, dash, dash, dash)}, {'k', string.Concat(dash, dot, dash)}, {'l', string.Concat(dot, dash, dot, dot)}, {'m', string.Concat(dash, dash)}, {'n', string.Concat(dash, dot)}, {'o', string.Concat(dash, dash, dash)}, {'p', string.Concat(dot, dash, dash, dot)}, {'q', string.Concat(dash, dash, dot, dash)}, {'r', string.Concat(dot, dash, dot)}, {'s', string.Concat(dot, dot, dot)}, {'t', string.Concat(dash)}, {'u', string.Concat(dot, dot, dash)}, {'v', string.Concat(dot, dot, dot, dash)}, {'w', string.Concat(dot, dash, dash)}, {'x', string.Concat(dash, dot, dot, dash)}, {'y', string.Concat(dash, dot, dash, dash)}, {'z', string.Concat(dash, dash, dot, dot)}, {'0', string.Concat(dash, dash, dash, dash, dash)}, {'1', string.Concat(dot, dash, dash, dash, dash)}, {'2', string.Concat(dot, dot, dash, dash, dash)}, {'3', string.Concat(dot, dot, dot, dash, dash)}, {'4', string.Concat(dot, dot, dot, dot, dash)}, {'5', string.Concat(dot, dot, dot, dot, dot)}, {'6', string.Concat(dash, dot, dot, dot, dot)}, {'7', string.Concat(dash, dash, dot, dot, dot)}, {'8', string.Concat(dash, dash, dash, dot, dot)}, {'9', string.Concat(dash, dash, dash, dash, dot)} }; } public static void getUserInput() { string input; Console.WriteLine("What did you want to say?"); input = Console.ReadLine(); input = input.ToLower(); Console.WriteLine("Your output is: " + translate(input)); Console.WriteLine("Press enter to end."); Console.ReadLine(); } private static string translate(string input) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach(char character in input) { if(translator.ContainsKey(character)) { sb.Append(translator[character] + " "); } else if (character == ' ') { sb.Append("/ "); } else { sb.Append(character + " "); } } return sb.ToString(); } } }
run
|
edit
|
history
|
help
0
הארות אופן שימוש
07-05-20
Linq FirstOrDefault() null check in c#
Метод catch b try в словарях
MIXED CONTENT - string and numbers separation in a large string
Types demo
GYT
Interviews
Clone Example
Sort the chars through LINQ