Advertisement
YORDAN2347

06._Wardrobe

Feb 13th, 2021
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06._Wardrobe
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var clothes = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13.             int n = int.Parse(Console.ReadLine());
  14.             clothes = ReadDictionary(clothes, n);
  15.  
  16.             string[] clothToFind = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); // ---??
  17.             string color = clothToFind[0];
  18.             string dress = clothToFind[1];
  19.  
  20.             PrintDictionary(clothes, color, dress);
  21.  
  22.         }
  23.  
  24.         private static void PrintDictionary(Dictionary<string, Dictionary<string, int>> clothes, string color, string dress)
  25.         {
  26.             foreach (var cloth in clothes)
  27.             {
  28.                 Console.WriteLine($"{cloth.Key} clothes:");
  29.                 foreach (var item in cloth.Value)
  30.                 {
  31.                     if (item.Key == dress && cloth.Key == color)
  32.                     {
  33.                         Console.WriteLine($"* {item.Key} - {item.Value} (found!)");
  34.                     }
  35.                     else
  36.                     {
  37.                         Console.WriteLine($"* {item.Key} - {item.Value}");
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.  
  43.         private static Dictionary<string, Dictionary<string, int>> ReadDictionary(Dictionary<string, Dictionary<string, int>> clothes, int n)
  44.         {
  45.             for (int i = 0; i < n; i++)
  46.             {
  47.                 string[] input = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
  48.                 string color = input[0];
  49.                 string[] clothesInput = input[1].Split(",");
  50.                 if (clothes.ContainsKey(color))
  51.                 {
  52.                     foreach (var cloth in clothesInput)
  53.                     {
  54.                         if (clothes[color].ContainsKey(cloth))
  55.                         {
  56.                             clothes[color][cloth]++;
  57.                         }
  58.                         else
  59.                         {
  60.                             clothes[color].Add(cloth, 1);
  61.                         }
  62.                     }
  63.                 }
  64.                 else
  65.                 {
  66.                     var temp = new Dictionary<string, int>();
  67.                     foreach (var item in clothesInput)
  68.                     {
  69.                         temp.Add(item, 1);
  70.                     }
  71.                     clothes.Add(color, temp);
  72.                 }
  73.             }
  74.             return clothes;
  75.         }
  76.     }
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement