Advertisement
Guest User

06. Wardrobe

a guest
Oct 18th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _06._Wardrobe
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
  14. for (int i = 0; i < n; i++)
  15. {
  16. var input = Console.ReadLine()
  17. .Split("->", StringSplitOptions.RemoveEmptyEntries).ToArray();
  18. string color = input[0];
  19. var clothes = input[1].Split(',', StringSplitOptions.RemoveEmptyEntries).ToArray();
  20. if (!dict.ContainsKey(color))
  21. {
  22. dict.Add(color, new Dictionary<string, int>());
  23. }
  24. for (int j = 0; j < clothes.Length; j++)
  25. {
  26. if (!dict[color].ContainsKey(clothes[j]))
  27. {
  28. dict[color].Add(clothes[j], 0);
  29. }
  30. dict[color][clothes[j]]++;
  31. }
  32. }
  33. var check = Console.ReadLine().Split().ToArray();
  34. string neededColor = check[0];
  35. string neededElement = check[1];
  36. foreach (var item in dict)
  37. {
  38.  
  39. Console.WriteLine($"{item.Key} clothes:");
  40. foreach (var element in item.Value)
  41. {
  42. Console.Write($"* {element.Key} - {element.Value}");
  43. if (element.Key == neededElement && item.Key == neededColor)
  44. {
  45. Console.Write("(found!)");
  46. }
  47.  
  48. Console.WriteLine();
  49. }
  50. }
  51. }
  52. }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement