Advertisement
Guest User

Untitled

a guest
May 27th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. namespace _06.Wardrobe
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6. public class Wardrobe
  7. {
  8. public static void Main()
  9. {
  10. var wardrobe = new Dictionary<string, Dictionary<string, int>>();
  11.  
  12. var numberOfLines = int.Parse(Console.ReadLine());
  13.  
  14. OrganiseWardrobe(wardrobe, numberOfLines);
  15.  
  16. var searchParameters = Console.ReadLine().Split();
  17. var desiredColor = searchParameters[0];
  18. var desiredClothing = searchParameters[1];
  19.  
  20. GoThroughWardrobe(wardrobe, desiredColor, desiredClothing);
  21. }
  22.  
  23. private static void GoThroughWardrobe(
  24. Dictionary<string, Dictionary<string, int>> wardrobe,
  25. string desiredColor,
  26. string desiredClothing)
  27. {
  28. foreach (var colorSection in wardrobe)
  29. {
  30. Console.WriteLine($"{colorSection.Key} clothes:");
  31.  
  32. foreach (var clothing in colorSection.Value)
  33. {
  34. Console.Write($"* {clothing.Key} - {clothing.Value}");
  35.  
  36. if (colorSection.Key == desiredColor && clothing.Key == desiredClothing)
  37. {
  38. Console.Write(" (found!)");
  39. }
  40.  
  41. Console.WriteLine();
  42. }
  43. }
  44. }
  45.  
  46. private static void OrganiseWardrobe(
  47. Dictionary<string, Dictionary<string, int>> wardrobe,
  48. int numberOfLines)
  49. {
  50. for (int i = 0; i < numberOfLines; i++)
  51. {
  52. var inputLine = Console.ReadLine().Split(" -> ");
  53. var color = inputLine[0];
  54. var clothes = inputLine[1].Split(",");
  55.  
  56. if (!wardrobe.ContainsKey(color))
  57. {
  58. wardrobe.Add(color, new Dictionary<string, int>());
  59. }
  60.  
  61. AddClothes(wardrobe, color, clothes);
  62. }
  63. }
  64.  
  65. private static void AddClothes(
  66. Dictionary<string, Dictionary<string, int>> wardrobe,
  67. string color,
  68. string[] clothes)
  69. {
  70. foreach (var piece in clothes)
  71. {
  72. if (!wardrobe[color].ContainsKey(piece))
  73. {
  74. wardrobe[color].Add(piece, 1);
  75. }
  76. else
  77. {
  78. wardrobe[color][piece]++;
  79. }
  80. }
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement