EmoRz

Problem 6. Wardrobe

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