Advertisement
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)
- {
- var clothes = new Dictionary<string, Dictionary<string, int>>();
- int n = int.Parse(Console.ReadLine());
- clothes = ReadDictionary(clothes, n);
- string[] clothToFind = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); // ---??
- string color = clothToFind[0];
- string dress = clothToFind[1];
- PrintDictionary(clothes, color, dress);
- }
- private static void PrintDictionary(Dictionary<string, Dictionary<string, int>> clothes, string color, string dress)
- {
- foreach (var cloth in clothes)
- {
- Console.WriteLine($"{cloth.Key} clothes:");
- foreach (var item in cloth.Value)
- {
- if (item.Key == dress && cloth.Key == color)
- {
- Console.WriteLine($"* {item.Key} - {item.Value} (found!)");
- }
- else
- {
- Console.WriteLine($"* {item.Key} - {item.Value}");
- }
- }
- }
- }
- private static Dictionary<string, Dictionary<string, int>> ReadDictionary(Dictionary<string, Dictionary<string, int>> clothes, int n)
- {
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
- string color = input[0];
- string[] clothesInput = input[1].Split(",");
- if (clothes.ContainsKey(color))
- {
- foreach (var cloth in clothesInput)
- {
- if (clothes[color].ContainsKey(cloth))
- {
- clothes[color][cloth]++;
- }
- else
- {
- clothes[color].Add(cloth, 1);
- }
- }
- }
- else
- {
- var temp = new Dictionary<string, int>();
- foreach (var item in clothesInput)
- {
- temp.Add(item, 1);
- }
- clothes.Add(color, temp);
- }
- }
- return clothes;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement