emilia98

Wardrobe - 1

Jul 15th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.Wardrobe
  6. {
  7.     class Wardrobe
  8.     {
  9.         static void Main()
  10.         {
  11.             Dictionary<string, Dictionary<string, int>> clothesData = new Dictionary<string, Dictionary<string, int>>();
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             for (int cnt = 0; cnt < n; cnt++)
  15.             {
  16.                 string[] input = Console.ReadLine().Split(new string[] { " -> " },
  17.                                                           StringSplitOptions.None).ToArray();
  18.                 string color = input[0];
  19.                 string[] clothesToAdd = input[1].Split(',').ToArray();
  20.  
  21.                 if (!clothesData.ContainsKey(color))
  22.                 {
  23.                     clothesData.Add(color, new Dictionary<string, int>());
  24.  
  25.                     for (int i = 0; i < clothesToAdd.Length; i++)
  26.                     {
  27.                         string clothesType = clothesToAdd[i];
  28.                         clothesData[color].Add(clothesType, 1);
  29.                     }
  30.                 }
  31.                 else
  32.                 {
  33.                     for (int i = 0; i < clothesToAdd.Length; i++)
  34.                     {
  35.                         string clothesType = clothesToAdd[i];
  36.                         if (!clothesData[color].ContainsKey(clothesType))
  37.                         {
  38.                             clothesData[color].Add(clothesType, 1);
  39.                         }
  40.                         else
  41.                         {
  42.                             clothesData[color][clothesType] += 1;
  43.                         }
  44.                     }
  45.                 }
  46.             }
  47.  
  48.             string[] itemToFind = Console.ReadLine().Split(' ').ToArray();
  49.             string itemToFindColor = itemToFind[0];
  50.             string itemToFindType = String.Empty;
  51.  
  52.             //Here, we form a string, in case we have a dress with more than one word
  53.             for (int index = 1; index < itemToFind.Length; index++)
  54.             {
  55.                 itemToFindType += itemToFind[index] + " ";
  56.             }
  57.             //Remove the space in the end, because int the check below, we won't have the right result
  58.             itemToFindType = itemToFindType.Remove(itemToFindType.Length - 1);
  59.  
  60.             foreach (var color in clothesData)
  61.             {
  62.                 string clothesColor = color.Key;
  63.                 Dictionary<string, int> clothesType = color.Value;
  64.                 Console.WriteLine("{0} clothes:", clothesColor);
  65.  
  66.                 foreach (var clothes in clothesType)
  67.                 {
  68.                     string clothingItem = clothes.Key;
  69.                     int clothingCount = clothes.Value;
  70.  
  71.                     if (clothesColor == itemToFindColor && clothingItem.CompareTo(itemToFindType) == 0)
  72.                     {
  73.                         Console.WriteLine("* {0} - {1} (found!)", clothingItem, clothingCount);
  74.                     }
  75.                     else
  76.                     {
  77.                         Console.WriteLine("* {0} - {1}", clothingItem, clothingCount);
  78.                     }
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment