Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace 06. Wardrobe
- {
- class Program
- {
- static void Main(string[] args)
- {
- int howMany = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, int>> wardrobe = new Dictionary<string, Dictionary<string, int>>();
- for (int i = 0; i < howMany; i++)
- {
- string[] input = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- string color = input[0];
- string[] clothes = input[1].Split(",", StringSplitOptions.RemoveEmptyEntries).ToArray();
- if (!wardrobe.ContainsKey(color))
- {
- wardrobe[color] = new Dictionary<string, int>();
- for (int typeCloth = 0; typeCloth < clothes.Length; typeCloth++)
- {
- if (wardrobe[color].ContainsKey(clothes[typeCloth]))
- {
- wardrobe[color][clothes[typeCloth]]++;
- }
- else
- {
- wardrobe[color][clothes[typeCloth]] = 1;
- }
- }
- }
- else
- {
- for (int typeCloth = 0; typeCloth < clothes.Length; typeCloth++)
- {
- if (wardrobe[color].ContainsKey(clothes[typeCloth]))
- {
- wardrobe[color][clothes[typeCloth]]++;
- }
- else
- {
- wardrobe[color][clothes[typeCloth]] = 1;
- }
- }
- }
- }
- string[] search = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- string searchedColor = search[0];
- string searchedType = search[1];
- foreach (var colorCloth in wardrobe)
- {
- Console.WriteLine($"{colorCloth.Key} clothes:");
- foreach (var type in colorCloth.Value)
- {
- if (searchedColor == colorCloth.Key && searchedType == type.Key)
- {
- Console.WriteLine($"* {type.Key} - {type.Value} (found!)");
- }
- else
- {
- Console.WriteLine($"* {type.Key} - {type.Value}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment