gabi11

Sets & Dictionaries Advanced - 06. Wardrobe

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