Advertisement
kalitarix

Wardrobe

Jan 23rd, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Wardrobe
  5. {
  6.     class Wardrobe
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Dictionary<string, Dictionary<string, int>> wardrobe = new Dictionary<string, Dictionary<string, int>>();
  11.  
  12.             int number = int.Parse(Console.ReadLine());
  13.  
  14.             for (int index = 0; index < number; index++)
  15.             {
  16.                 string[] clothesLine = Console.ReadLine().Split(" -> ");
  17.                 string color = clothesLine[0];
  18.                 string[] clothes = clothesLine[1].Split(",");
  19.  
  20.                 if (wardrobe.ContainsKey(color) == false)
  21.                 {
  22.                     wardrobe.Add(color, new Dictionary<string, int>());
  23.                 }
  24.  
  25.                 foreach (string item in clothes)
  26.                 {
  27.                     if (wardrobe[color].ContainsKey(item) == false)
  28.                     {
  29.                         wardrobe[color].Add(item, 0);
  30.                     }
  31.  
  32.                     wardrobe[color][item]++;
  33.                 }
  34.             }
  35.  
  36.             string[] wanted = Console.ReadLine().Split();
  37.             string colorNeeded = wanted[0];
  38.             string itemNeeded = wanted[1];
  39.  
  40.             foreach (var color in wardrobe)
  41.             {
  42.                 Console.WriteLine($"{color.Key} clothes:");
  43.  
  44.                 Dictionary<string, int> clothesLine = color.Value;
  45.  
  46.                 foreach (var item in clothesLine)
  47.                 {
  48.                     string output = $"* {item.Key} - {item.Value}";
  49.  
  50.                     if (colorNeeded == color.Key && itemNeeded == item.Key)
  51.                     {
  52.                         output += " (found!)";
  53.                     }
  54.  
  55.                     Console.WriteLine(output);
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement