Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace demo
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> input = Console.ReadLine().Split(new string[] { "->", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
- string command = input[0];
- Dictionary<string, List<string>> diary = new Dictionary<string, List<string>>();
- while (command != "END")
- {
- if (command == "Add")
- {
- string store = input[1];
- if (input.Count == 3)
- {
- if (!diary.ContainsKey(store))
- {
- diary[store] = new List<string>();
- diary[store].Add(input[2]);
- }
- diary[store].Add(input[2]);
- }
- else if (input.Count > 3)
- {
- if (!diary.ContainsKey(store))
- {
- diary[store] = new List<string>();
- }
- for (int i = 2; i < input.Count; i++)
- {
- diary[store].Add(input[i]);
- }
- }
- }
- else if (command == "Remove")
- {
- string store = input[1];
- if (diary.ContainsKey(store))
- {
- diary.Remove(store);
- }
- }
- input = Console.ReadLine().Split(new string[] { "->", "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
- command = input[0];
- }
- Console.WriteLine("Store list:");
- diary = diary.OrderByDescending(x => x.Value).ThenByDescending(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
- foreach (var item in diary)
- {
- Console.WriteLine(item.Key);
- for (int i = 0; i < item.Value.Count; i++)
- {
- Console.WriteLine(item.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement