Advertisement
Lazov

06._Wardrobe

Jan 26th, 2019
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _06._Wardrobe
  5. {
  6. class Wardrobe
  7. {
  8. static void Main(string[] args)
  9. {
  10. int lines = int.Parse(Console.ReadLine());
  11. var colorClothCount = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. for (int i = 0; i < lines; i++)
  14. {
  15. string[] colorClotes = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
  16.  
  17. string color = colorClotes[0];
  18. string[] clothes = colorClotes[1].Split(',');
  19.  
  20. if (colorClothCount.ContainsKey(color) == false) // !colorClothCount.ContainsKey(color)
  21. {
  22. colorClothCount[color] = new Dictionary<string, int>();
  23. }
  24.  
  25. for (int j = 0; j < clothes.Length; j++)
  26. {
  27. string cloth = clothes[j];
  28. if (!colorClothCount[color].ContainsKey(cloth))
  29. {
  30. colorClothCount[color][cloth] = 0;
  31. }
  32.  
  33. colorClothCount[color][cloth]++;
  34. }
  35.  
  36. }
  37.  
  38. string[] search = Console.ReadLine().Split();
  39.  
  40. string colorToSearch = search[0];
  41. string clothToSearch = search[1];
  42.  
  43. foreach (var kvp in colorClothCount)
  44. {
  45. string color = kvp.Key;
  46. var clothCount = kvp.Value;
  47. Console.WriteLine($"{color} clothes:");
  48.  
  49. foreach (var kvpClothCount in clothCount)
  50. {
  51. string cloth = kvpClothCount.Key;
  52. int count = kvpClothCount.Value;
  53.  
  54. if (clothToSearch == cloth && clothToSearch == cloth)
  55. {
  56. Console.WriteLine($"* {cloth} - {count} (found!)");
  57. }
  58. else
  59. {
  60. Console.WriteLine($"* {cloth} - {count}");
  61. }
  62. }
  63. }
  64.  
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement