Advertisement
Guest User

Wardrobe

a guest
Jul 11th, 2017
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 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 clothes2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> clothes = new Dictionary<string, Dictionary<string, int>>();
  14.             int numberOfEntries = int.Parse(Console.ReadLine());
  15.             for (int br = 0; br < numberOfEntries; br++)
  16.             {
  17.                 string[] intro = Console.ReadLine().Split(' ');
  18.                 string color = intro[0];
  19.                 string[] clothesSameColour = intro[2].Split(',').ToArray();
  20.                 if (!clothes.ContainsKey(color))
  21.                 {
  22.                     clothes.Add(color, new Dictionary<string, int>());
  23.                 }
  24.  
  25.                 foreach (var cloth in clothesSameColour)
  26.                 {
  27.                     Dictionary<string, int> clothDB = clothes[color];
  28.                     if (!clothDB.ContainsKey(cloth))
  29.                         clothDB.Add(cloth,0);
  30.                     clothDB[cloth]++;
  31.                 }
  32.             }
  33.             string[] tosearchfor = Console.ReadLine().Split(' ');
  34.             foreach (KeyValuePair<string,Dictionary<string,int>> item in clothes)
  35.             {
  36.                 string color = item.Key;
  37.                 Dictionary<string, int> dataClothes = item.Value;
  38.                 Console.WriteLine("{0} clothes:", color);
  39.                 foreach (KeyValuePair<string,int> item2 in dataClothes)
  40.                 {
  41.                     string cloth = item2.Key;
  42.                     int times = item2.Value;
  43.                     Console.Write("* {0} - {1} ", cloth, times);
  44.                     if (color == tosearchfor[0] && tosearchfor[1] == cloth)
  45.                         Console.Write("(found!)");
  46.                     Console.WriteLine();
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement