Aliendreamer

wardrobe

Jul 10th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _01NestedDictionariesExcercisesWardrobe
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Dictionary<string, Dictionary<string, int>> clothes = new Dictionary<string, Dictionary<string, int>>();
  15.  
  16.             int num = int.Parse(Console.ReadLine());
  17.  
  18.             for (int i = 0; i < num; i++)
  19.             {
  20.                 string[] inputTokens = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  21.  
  22.                 string color = inputTokens[0];
  23.                 string[] allDresses = inputTokens[1].Split(',').ToArray();
  24.                 string cloth = string.Empty;
  25.  
  26.                 for (int j =0; j <allDresses.Length; j++)
  27.                 {
  28.                  
  29.                    cloth = allDresses[j];
  30.  
  31.  
  32.                     if (!clothes.ContainsKey(color))
  33.                     {
  34.                         clothes.Add(color, new Dictionary<string, int>());
  35.                         clothes[color].Add(cloth, 1);
  36.                     }
  37.                     else
  38.                     {
  39.                         if(!clothes[color].ContainsKey(cloth))
  40.                         {
  41.                             clothes[color].Add(cloth, 1);
  42.                         }
  43.                         else
  44.                         {
  45.                             clothes[color][cloth] ++;
  46.                         }
  47.  
  48.  
  49.                     }
  50.                  
  51.  
  52.                 }
  53.             }
  54.             // input and filling the data done :D if proverkite neshto gurmqt
  55.  
  56.             string[] marker = Console.ReadLine().Split(' ').ToArray();
  57.             string markerColor = marker[0];
  58.             string markerCloth = marker[1];
  59.  
  60.             foreach (KeyValuePair<string,Dictionary<string,int>> pair in clothes)
  61.             {
  62.                 string colour = pair.Key;
  63.                 Console.WriteLine($"{colour} clothes:");
  64.  
  65.                 Dictionary<string, int> wardrobeclothes = pair.Value;
  66.  
  67.                 foreach(KeyValuePair<string,int>kvp in wardrobeclothes)
  68.                 {
  69.                     string dress = kvp.Key;
  70.                     int count = kvp.Value;
  71.                     if(colour==markerColor && dress==markerCloth)
  72.                     {
  73.                         Console.WriteLine($"* {dress} - {count} (found!)");
  74.                     }
  75.                     else
  76.                     {
  77.                         Console.WriteLine($"* {dress} - {count}");
  78.                     }
  79.  
  80.                 }
  81.  
  82.  
  83.             }
  84.             //output-a raboti samo logikata da oprava
  85.         }
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment