Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Santa_sHelper
- {
- class Program
- {
- static Queue<string> comandResult = new Queue<string>();
- static Dictionary<string, List<Tuple<string, double>>> santaList = new Dictionary<string, List<Tuple<string, double>>>();
- static void Main(string[] args)
- {
- int commandNumber = int.Parse(Console.ReadLine());
- string input;
- for (int i = 0; i < commandNumber; i++)
- {
- input = Console.ReadLine();
- switch (input.Split()[0])
- {
- case "AddWish":
- AddWish(input.Substring(8));
- break;
- case "DeleteWishes":
- DeleteWishes(input.Substring(13));
- break;
- case "FindWishesByPriceRange":
- WishesInPriceRange(input.Substring(23));
- break;
- case "FindWishesByChild":
- WishesByChildren(input.Substring(18));
- break;
- default:
- break;
- }
- }
- Console.WriteLine(string.Join(Environment.NewLine, comandResult));
- }
- private static void AddWish(string wish)
- {
- string item = wish.Split(';')[0];
- double price = double.Parse(wish.Split(';')[1]);
- string child = wish.Split(';')[2];
- Tuple<string, double> itemInfo = new Tuple<string, double>(item, price);
- if (santaList.ContainsKey(child))
- {
- santaList[child].Add(itemInfo);
- }
- else
- {
- santaList.Add(child, new List<Tuple<string, double>>());
- santaList[child].Add(itemInfo);
- }
- comandResult.Enqueue("Wish added");
- }
- private static void DeleteWishes(string child)
- {
- int wishes;
- if (santaList.ContainsKey(child))
- {
- wishes = santaList[child].Count;
- santaList.Remove(child);
- comandResult.Enqueue($"{wishes} Wishes deleted");
- }
- else
- {
- comandResult.Enqueue("No Wishes found");
- }
- }
- private static void WishesInPriceRange(string prices)
- {
- List<string> items = new List<string>();
- double min = double.Parse(prices.Split(';')[0]);
- double max = double.Parse(prices.Split(';')[1]);
- foreach (var child in santaList)
- {
- foreach (var wish in child.Value)
- {
- if (wish.Item2 >= min && wish.Item2 <= max)
- {
- items.Add("{" + $"{wish.Item1};{child.Key};{wish.Item2:0.00}" + "}");
- }
- }
- }
- if (items.Count > 0)
- {
- items.Sort();
- comandResult.Enqueue(string.Join(Environment.NewLine, items));
- }
- else
- {
- comandResult.Enqueue("No Wishes found");
- }
- }
- private static void WishesByChildren(string child)
- {
- List<string> items = new List<string>();
- if (santaList.ContainsKey(child))
- {
- foreach (var wish in santaList[child])
- {
- items.Add("{" + $"{wish.Item1};{child};{wish.Item2:0.00}" + "}");
- }
- items.Sort();
- comandResult.Enqueue(string.Join(Environment.NewLine, items));
- }
- else
- {
- comandResult.Enqueue("No Wishes found");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment