Advertisement
alexbancheva

Problem 1. Dictionary_FinalExam_06.04

Apr 1st, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. namespace _1.Dictionary_FinalExam_06._04._2019
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
  13.  
  14.             string input = Console.ReadLine();
  15.             string inputWord = Console.ReadLine();
  16.             string endLine = Console.ReadLine();
  17.  
  18.  
  19.             //while (input != "List" || input != "End")
  20.             //{   // string definition = word[1];// }
  21.  
  22.             string[] word = input.Split(" | ");
  23.  
  24.                 for (int i = 0; i < word.Length; i++)
  25.                 {
  26.  
  27.                     string[] newWord = word[i].Split(": ");
  28.  
  29.                     string wordKey = newWord[0];
  30.                     string def = newWord[1];
  31.  
  32.                     if (!dict.ContainsKey(wordKey))
  33.                     {
  34.                    
  35.                     dict[wordKey] = new List<string>();
  36.  
  37.                     }
  38.                
  39.                     dict[wordKey].Add(def);
  40.  
  41.                 }
  42.  
  43.            
  44.             string[] splitedInputW = inputWord.Split(" | ");
  45.  
  46.             for (int i = 0; i < splitedInputW.Length; i++)
  47.             {
  48.  
  49.                 string findWord = splitedInputW[i];
  50.  
  51.                 if (dict.ContainsKey(findWord))
  52.                 {
  53.  
  54.  
  55.                     foreach (var item in dict.OrderBy(x => x.Key))
  56.                     {
  57.                         Console.WriteLine($"{item.Key} ");
  58.  
  59.                         foreach (var definition in item.Value.OrderByDescending(x=>x.Length))
  60.                         {
  61.                             Console.WriteLine($" -{definition}");
  62.                         }
  63.  
  64.                         //foreach (var definition in dict.Values.OrderByDescending(x => x))
  65.                         //{
  66.                         //    Console.WriteLine($" --{definition}");
  67.                         //}
  68.                     }
  69.  
  70.                 }
  71.                 break;
  72.  
  73.             }
  74.  
  75.            
  76.  
  77.             if (endLine == "List")
  78.             {
  79.  
  80.                 foreach (var item in dict.OrderBy(x => x.Key))
  81.                 {
  82.  
  83.                     Console.Write($"{item.Key} ");
  84.  
  85.                 }
  86.  
  87.  
  88.             }
  89.            
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement