Daniel_007

06. Wardrobe

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