Advertisement
Guest User

solution

a guest
Oct 1st, 2021
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. Dictionary<string, Dictionary<string, int>> wardrobe =
  11. new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. for (int i = 0; i < n; i++)
  14. {
  15. List<string> input = Console.ReadLine()
  16. .Split(" -> ",StringSplitOptions.RemoveEmptyEntries).ToList();
  17. string colour = input[0];
  18. string[] clothes = input[1].Split(",",StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20. if (!wardrobe.ContainsKey(colour))
  21. {
  22. wardrobe.Add(colour, new Dictionary<string, int>());
  23. for (int k = 0; k < clothes.Length; k++)
  24. {
  25. if (wardrobe[colour].ContainsKey(clothes[k]))
  26. {
  27. wardrobe[colour][clothes[k]]++;
  28. }
  29. else
  30. {
  31. wardrobe[colour].Add(clothes[k], 1);
  32.  
  33. }
  34. }
  35. }
  36. else
  37. {
  38. for (int k = 0; k < clothes.Length; k++)
  39. {
  40. if (wardrobe[colour].ContainsKey(clothes[k]))
  41. {
  42. wardrobe[colour][clothes[k]]++;
  43. }
  44. else
  45. {
  46. wardrobe[colour].Add(clothes[k], 1);
  47. }
  48. }
  49.  
  50. }
  51. }
  52. List<string> itemToFind = Console.ReadLine()
  53. .Split().ToList();
  54.  
  55. foreach (var item in wardrobe)
  56. {
  57. Console.WriteLine($"{item.Key} clothes:");
  58. foreach (var clothe in item.Value)
  59. {
  60. if (item.Key == itemToFind[0] && clothe.Key == itemToFind[1])
  61. {
  62. Console.WriteLine($"* {clothe.Key} - {clothe.Value} (found!)");
  63. }
  64. else
  65. {
  66. Console.WriteLine($"* {clothe.Key} - {clothe.Value}");
  67. }
  68. }
  69.  
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement