Advertisement
yanass

Wardrobe - Sets and Dictionaries Advanced

Oct 4th, 2019
527
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 Wardrobe
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. int numClothes = int.Parse(Console.ReadLine());
  12.  
  13. Dictionary<string, Dictionary<string, int>> colorsWardrobe
  14. = new Dictionary<string, Dictionary<string, int>>();
  15.  
  16. for (int i = 0; i < numClothes; i++)
  17. {
  18. string[] input = Console.ReadLine()
  19. .Split(" -> ");
  20. string color = input[0];
  21. string[] clothes = input[1].Split(",");
  22.  
  23. if (!colorsWardrobe.ContainsKey(color))
  24. {
  25. colorsWardrobe[color] = new Dictionary<string, int>();
  26. }
  27.  
  28. var colorCollection = colorsWardrobe[color];
  29.  
  30. for (int j = 0; j < clothes.Length; j++)
  31. {
  32. if (!colorCollection.ContainsKey(clothes[j]))
  33. {
  34. colorCollection[clothes[j]] = 0;
  35. }
  36. colorCollection[clothes[j]]++;
  37. }
  38. }
  39.  
  40. string[] itemNeeded = Console.ReadLine().Split();
  41.  
  42. string colorNeeded = itemNeeded[0];
  43. string pieceNeeded = itemNeeded[1];
  44.  
  45. foreach (var color in colorsWardrobe)
  46. {
  47. Console.WriteLine($"{color.Key} clothes:");
  48.  
  49. foreach (var clothes in color.Value)
  50. {
  51. Console.WriteLine(color.Key == colorNeeded && clothes.Key == pieceNeeded
  52. ? $"* {clothes.Key} - {clothes.Value} (found!)"
  53. : $"* {clothes.Key} - {clothes.Value}");
  54. }
  55. }
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement