YavorGrancharov

Wardrobe(copy)(nested_dict)

Jul 11th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 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 Wardrobe
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> wordrobe = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 string[] input = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.                 string color = input[0];
  21.                 string[] item = input[1].Split(',');
  22.  
  23.                 if (!wordrobe.ContainsKey(color))
  24.                 {
  25.                     wordrobe.Add(color, new Dictionary<string, int>());
  26.                 }
  27.                 foreach (string cloth in item)
  28.                 {
  29.                     Dictionary<string, int> dataBase = wordrobe[color];
  30.                     if (!dataBase.ContainsKey(cloth))
  31.                     {
  32.                         dataBase.Add(cloth, 0);
  33.                     }
  34.                     dataBase[cloth]++;
  35.                 }
  36.             }
  37.             string[] search = Console.ReadLine().Split(' ');
  38.             string searchColor = search[0];
  39.             string searchCloth = search[1];
  40.  
  41.             foreach (KeyValuePair<string, Dictionary<string, int>> colorData in wordrobe)
  42.             {
  43.                 string color = colorData.Key;
  44.                 Dictionary<string, int> clothsData = colorData.Value;
  45.                 Console.WriteLine("{0} clothes:", color);
  46.                 foreach (KeyValuePair<string, int> clothData in clothsData)
  47.                 {
  48.                     string cloth = clothData.Key;
  49.                     int count = clothData.Value;
  50.  
  51.                     Console.Write("* {0} - {1}", cloth, count);
  52.                     if (color == searchColor && cloth == searchCloth)
  53.                     {
  54.                         Console.Write(" (found!)");
  55.                     }
  56.                     Console.WriteLine();
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment