Advertisement
Guest User

Wardrobe

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