Advertisement
Guest User

TOPASIMI

a guest
Dec 15th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             List<string> dankalove = Console.ReadLine().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  15.             string[] words = Console.ReadLine().Split(new[] { '|', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  16.             string command = Console.ReadLine();
  17.  
  18.             Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
  19.             for (int i = 0; i < dankalove.Count; i++)
  20.             {
  21.                 string[] temporary = dankalove[i].Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  22.                 temporary[0] = temporary[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray()[0];
  23.                 if (dictionary.ContainsKey(temporary[0]))
  24.                 {
  25.                     List<string> previous = dictionary[temporary[0]];
  26.                     previous.Add(temporary[1]);
  27.                     dictionary[temporary[0]] = previous;
  28.                 }else
  29.                 {
  30.                     List<string> definition = new List<string>();
  31.                     definition.Add(temporary[1]);
  32.                     dictionary.Add(temporary[0], definition);
  33.                 }
  34.                
  35.             }
  36.             if(command == "List")
  37.             {
  38.                 var wordsOutput = dictionary.Keys.ToList();
  39.                 wordsOutput.Sort();
  40.                 for(int i = 0; i < wordsOutput.Count; i++)
  41.                 {
  42.                     Console.Write(wordsOutput[i] + " ");
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.             if(command == "End")
  47.             {
  48.                 var wordsOutput = dictionary.Keys.ToList();
  49.                 wordsOutput.Sort();
  50.                 for (int i = 0; i < wordsOutput.Count; i++)
  51.                 {
  52.                     Console.WriteLine(wordsOutput[i]);
  53.                     var definitions = dictionary[wordsOutput[i]];
  54.                     definitions.Sort();
  55.                     for (int j = 0; j < definitions.Count; j++)
  56.                     {
  57.                         Console.Write(" " + "-" + definitions[j].Substring(1));
  58.                        
  59.                         Console.WriteLine();
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement