Advertisement
Guest User

Untitled

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