emilia98

Wardobe - 2

Jul 15th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01.Wardrobe_2
  6. {
  7.     class Wardrobe_2
  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.                 for (int i = 0; i < clothesToAdd.Length; i++)
  22.                 {
  23.                     string clothesType = clothesToAdd[i];
  24.  
  25.                     if (!clothesData.ContainsKey(color))
  26.                     {
  27.                         clothesData.Add(color, new Dictionary<string, int>());
  28.                         clothesData[color].Add(clothesType, 1);
  29.                     }
  30.                     else
  31.                     {
  32.                         if (!clothesData[color].ContainsKey(clothesType))
  33.                         {
  34.                             clothesData[color].Add(clothesType, 1);
  35.                         }
  36.                         else
  37.                         {
  38.                             clothesData[color][clothesType] += 1;
  39.                         }
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             string[] itemToFind = Console.ReadLine().Split(' ').ToArray();
  45.             string itemToFindColor = itemToFind[0];
  46.             string itemToFindType = itemToFind[1];
  47.            
  48.             foreach (var color in clothesData)
  49.             {
  50.                 string clothesColor = color.Key;
  51.                 Dictionary<string, int> clothesType = color.Value;
  52.                 Console.WriteLine("{0} clothes:", clothesColor);
  53.  
  54.                 foreach (var clothes in clothesType)
  55.                 {
  56.                     string clothingItem = clothes.Key;
  57.                     int clothingCount = clothes.Value;
  58.  
  59.                     if (clothesColor == itemToFindColor && clothingItem.CompareTo(itemToFindType) == 0)
  60.                     {
  61.                         Console.WriteLine("* {0} - {1} (found!)", clothingItem, clothingCount);
  62.                     }
  63.                     else
  64.                     {
  65.                         Console.WriteLine("* {0} - {1}", clothingItem, clothingCount);
  66.                     }
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment