Advertisement
EmoRz

Problem 6. Wardrobe

Sep 29th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.56 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(">".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  17.                 string color = parts[0];
  18.                 string[] temp = parts[1].Replace(',',' ').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.                     var r = 1;
  47.                     Console.WriteLine($"{color.Key.Split("-".ToCharArray())[0].Trim()} clothes:");
  48.  
  49.  
  50.                     if (color.Key.Contains(searched[0]))
  51.                     {
  52.  
  53.                         foreach (var clouths in color.Value)
  54.                         {
  55.                             if (clouths.Key == searched[1])
  56.                             {
  57.                                 Console.WriteLine("* " + clouths.Key + " - {0} (found!)", clouths.Value);
  58.  
  59.  
  60.                             }
  61.                             else
  62.                             {
  63.                                 Console.WriteLine("* " + clouths.Key + " - {0}", clouths.Value);
  64.  
  65.                             }
  66.  
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                         foreach (var clouths in color.Value)
  72.                         {
  73.                             Console.WriteLine("* " + clouths.Key + " - {0}", clouths.Value);
  74.                         }
  75.                     }
  76.  
  77.  
  78.                 }
  79.             }
  80.            
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement