alexbancheva

Wardrobe_Exercises_Sets_and_Dictionaries

Mar 30th, 2021
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Wardrobe_Exercises_Sets_and_Dictionaries
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             Dictionary<string, Dictionary<string, int>> wardrobe = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 string[] inputData = Console.ReadLine()
  16.                     .Split(" -> ");
  17.                 string color = inputData[0];
  18.                 string[] dresses = inputData[1].Split(",");
  19.  
  20.                 if (!wardrobe.ContainsKey(color))
  21.                 {
  22.  
  23.                     wardrobe.Add(color, new Dictionary<string, int>());
  24.  
  25.                 }
  26.                
  27.                 foreach (var dress in dresses)
  28.                 {
  29.                     if (!wardrobe[color].ContainsKey(dress))
  30.                     {
  31.                         wardrobe[color].Add(dress, 0);
  32.                     }
  33.                     wardrobe[color][dress]++;
  34.                 }
  35.             }
  36.             string[] findingDress = Console.ReadLine().Split(" ");
  37.             string enteredColor = findingDress[0];
  38.             string clothing = findingDress[1];
  39.  
  40.             foreach (var (color, values) in wardrobe)
  41.             {
  42.                 Console.WriteLine($"{color} clothes:");
  43.                 Dictionary<string, int> clothes = values;
  44.  
  45.                 foreach (var dress in clothes)
  46.                 {
  47.                     string result = $"* {dress.Key} - {dress.Value}";
  48.  
  49.                     if (enteredColor == color && clothing == dress.Key)
  50.                     {
  51.                         result += " (found!)";
  52.                     }
  53.  
  54.                     Console.WriteLine(result);
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment