Advertisement
Guest User

Problem 6. Wardrobe

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