Advertisement
AleksPopov

wardrobe

Jan 23rd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 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.             var number = int.Parse(Console.ReadLine());
  12.  
  13.             var wardrobe = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             bool clothesForAdd = false;
  16.             for (int i = 0; i < number; i++)
  17.             {
  18.                 string[] command = Console.ReadLine().Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
  19.                 string color = command[0];
  20.  
  21.                 if (!wardrobe.ContainsKey(color))
  22.                 {
  23.                     wardrobe.Add(color, new Dictionary<string, int>());
  24.  
  25.                 }
  26.  
  27.  
  28.                 string[] clothes = command[1].Split(',', StringSplitOptions.RemoveEmptyEntries);
  29.  
  30.                 if (!clothesForAdd)
  31.                 {
  32.                     for (int y = 0; y < clothes.Length; y++)
  33.                     {
  34.                         string item = clothes[y];
  35.                         if (!wardrobe[color].ContainsKey(item))
  36.                         {
  37.                             wardrobe[color].Add(item, 1);
  38.                         }
  39.                         else
  40.                         {
  41.                             wardrobe[color][item] += 1;
  42.                         }
  43.                     }
  44.                 }
  45.  
  46.             }
  47.  
  48.             string[] input = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  49.  
  50.             string colors = input[0];
  51.             string clothesForResult = input[1];
  52.  
  53.             foreach (var items in wardrobe)
  54.             {
  55.                 Console.WriteLine($"{items.Key} clothes:");
  56.                 foreach (var item in items.Value)
  57.                 {
  58.                     Console.Write($"* {item.Key} - {item.Value}");
  59.                     if (items.Key == colors && item.Key == clothesForResult)
  60.                     {
  61.                         Console.Write(" (found!)");
  62.                     }
  63.                     Console.WriteLine();
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement