Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Problem_6._Wardrobe
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfClothes = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, int>> allClothes = new Dictionary<string, Dictionary<string, int>>();
- FillWardrobe(allClothes, numberOfClothes);
- string[] searchingCloth = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
- string color = searchingCloth[0];
- string clothing = searchingCloth[1];
- PrintWardrobe(allClothes, color, clothing);
- }
- static void PrintWardrobe(Dictionary<string, Dictionary<string, int>> allClothes, string color, string clothing)
- {
- foreach (var currentCloth in allClothes)
- {
- Console.WriteLine($"{currentCloth.Key} clothes:");
- foreach (var cloth in currentCloth.Value)
- {
- if (color == currentCloth.Key && clothing == cloth.Key)
- {
- Console.WriteLine($"* {cloth.Key} - {cloth.Value} (found!)");
- }
- else
- {
- Console.WriteLine($"* {cloth.Key} - {cloth.Value}");
- }
- }
- }
- }
- static Dictionary<string, Dictionary<string,int>> FillWardrobe(Dictionary<string, Dictionary<string, int>> allClothes, int numberOfClothes)
- {
- for (int i = 0; i < numberOfClothes; i++)
- {
- string[] input = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
- string currentColor = input[0]; // blue
- string[] items = input[1].Split(",", StringSplitOptions.RemoveEmptyEntries); //dress,pants,jeans
- if (allClothes.ContainsKey(currentColor) == false)
- {
- allClothes.Add(currentColor, new Dictionary<string, int>());
- }
- for (int cloth = 0; cloth < items.Length; cloth++)
- {
- string currentCloth = items[cloth];
- if (allClothes[currentColor].ContainsKey(currentCloth) == false)
- {
- allClothes[currentColor].Add(currentCloth, 0);
- }
- allClothes[currentColor][currentCloth]++;
- }
- }
- return allClothes;
- }
- }
- }
Add Comment
Please, Sign In to add comment