Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.Wardrobe
- {
- class Wardrobe
- {
- static void Main()
- {
- Dictionary<string, Dictionary<string, int>> clothesData = new Dictionary<string, Dictionary<string, int>>();
- int n = int.Parse(Console.ReadLine());
- for (int cnt = 0; cnt < n; cnt++)
- {
- string[] input = Console.ReadLine().Split(new string[] { " -> " },
- StringSplitOptions.None).ToArray();
- string color = input[0];
- string[] clothesToAdd = input[1].Split(',').ToArray();
- if (!clothesData.ContainsKey(color))
- {
- clothesData.Add(color, new Dictionary<string, int>());
- for (int i = 0; i < clothesToAdd.Length; i++)
- {
- string clothesType = clothesToAdd[i];
- clothesData[color].Add(clothesType, 1);
- }
- }
- else
- {
- for (int i = 0; i < clothesToAdd.Length; i++)
- {
- string clothesType = clothesToAdd[i];
- if (!clothesData[color].ContainsKey(clothesType))
- {
- clothesData[color].Add(clothesType, 1);
- }
- else
- {
- clothesData[color][clothesType] += 1;
- }
- }
- }
- }
- string[] itemToFind = Console.ReadLine().Split(' ').ToArray();
- string itemToFindColor = itemToFind[0];
- string itemToFindType = String.Empty;
- //Here, we form a string, in case we have a dress with more than one word
- for (int index = 1; index < itemToFind.Length; index++)
- {
- itemToFindType += itemToFind[index] + " ";
- }
- //Remove the space in the end, because int the check below, we won't have the right result
- itemToFindType = itemToFindType.Remove(itemToFindType.Length - 1);
- foreach (var color in clothesData)
- {
- string clothesColor = color.Key;
- Dictionary<string, int> clothesType = color.Value;
- Console.WriteLine("{0} clothes:", clothesColor);
- foreach (var clothes in clothesType)
- {
- string clothingItem = clothes.Key;
- int clothingCount = clothes.Value;
- if (clothesColor == itemToFindColor && clothingItem.CompareTo(itemToFindType) == 0)
- {
- Console.WriteLine("* {0} - {1} (found!)", clothingItem, clothingCount);
- }
- else
- {
- Console.WriteLine("* {0} - {1}", clothingItem, clothingCount);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment