Advertisement
ralichka

Untitled

Dec 4th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace demo
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<string> input = Console.ReadLine().Split(new string[] { "->", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
  12.  
  13.             string command = input[0];
  14.  
  15.             Dictionary<string, List<string>> diary = new Dictionary<string, List<string>>();
  16.  
  17.             while (command != "END")
  18.             {
  19.  
  20.                 if (command == "Add")
  21.                 {
  22.                     string store = input[1];
  23.                     if (input.Count == 3)
  24.                     {
  25.                         if (!diary.ContainsKey(store))
  26.                         {
  27.                             diary[store] = new List<string>();
  28.                             diary[store].Add(input[2]);
  29.                         }
  30.                         diary[store].Add(input[2]);
  31.                     }
  32.                     else if (input.Count > 3)
  33.                     {
  34.                         if (!diary.ContainsKey(store))
  35.                         {
  36.                             diary[store] = new List<string>();
  37.                         }
  38.                         for (int i = 2; i < input.Count; i++)
  39.                         {
  40.                             diary[store].Add(input[i]);
  41.                         }
  42.                     }
  43.                 }
  44.                 else if (command == "Remove")
  45.                 {
  46.                     string store = input[1];
  47.                     if (diary.ContainsKey(store))
  48.                     {
  49.                         diary.Remove(store);
  50.                     }
  51.                 }
  52.  
  53.                 input = Console.ReadLine().Split(new string[] { "->", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
  54.                 command = input[0];
  55.                
  56.             }
  57.  
  58.             Console.WriteLine("Store list:");
  59.             diary = diary.OrderByDescending(x => x.Value).ThenByDescending(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  60.  
  61.             foreach (var item in diary)
  62.             {
  63.                 Console.WriteLine(item.Key);
  64.                 for (int i = 0; i < item.Value.Count; i++)
  65.                 {
  66.                     Console.WriteLine(item.Value);
  67.                 }
  68.             }
  69.  
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement