Advertisement
gospod1978

Final Exam/On the Way to Annapurna

Oct 23rd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace fundamental14
  8. {
  9.     class MainClass
  10.     {
  11.         public static void Main()
  12.         {
  13.  
  14.             Dictionary<string, List<string>> store = new Dictionary<string, List<string>>();
  15.  
  16.             string input = string.Empty;
  17.  
  18.             while((input = Console.ReadLine()) != "END")
  19.             {
  20.                 string[] arry = input.Split("->").ToArray();
  21.                 string command = arry[0];
  22.                 string storeList = arry[1];
  23.  
  24.                 if (command == "Add")
  25.                 {
  26.                     List<string> items = arry[2].Split(",").ToList();
  27.  
  28.                     if(!store.ContainsKey(storeList))
  29.                     {
  30.                         store.Add(storeList, items);
  31.                     }
  32.                     else
  33.                     {
  34.                         foreach (var item in items)
  35.                         {                        
  36.                             store[storeList].Add(item);
  37.                         }
  38.                        
  39.                     }
  40.                 }
  41.                 else
  42.                 {
  43.                     if(store.ContainsKey(storeList))
  44.                     {
  45.                         store.Remove(storeList);
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             Console.WriteLine("Stores list:");
  51.  
  52.             foreach (var kvp in store.OrderByDescending(x => x.Value.Count).ThenByDescending(x => x.Key))
  53.             {
  54.                 Console.WriteLine($"{kvp.Key}");
  55.                 foreach (var product in kvp.Value)
  56.                 {
  57.                     Console.WriteLine($"<<{product}>>");
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement