Advertisement
grubcho

Wardrobe

Jul 14th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.97 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. //On the first line of the input, you will receive n –  the number of lines of clothes, which came prepackaged for the wardrobe.
  7. //On the next n lines, you will receive the clothes for each color in the format:
  8. //•   “{color} -> {item1},{item2},{item3}…”
  9. //If a color is added a second time, add all items from it and count the duplicates.
  10. //Finally, you will receive the color and item of the clothing, that you need to look for.
  11. //Output
  12. //Go through all the colors of the clothes and print them in the following format:
  13. //{color} clothes:
  14. //* {item1} - {count}
  15. //* {item2} - {count}
  16. //* {item3} - {count}
  17. //If the color lines up with the clothing item, print “(found!)” alongside the item. See the examples to better understand the output.
  18.  
  19. namespace Wardrobe
  20. {
  21.     class Program
  22.     {
  23.         static void Main(string[] args)
  24.         {
  25.             Dictionary<string, Dictionary<string, int>> wardrobe = new Dictionary<string, Dictionary<string, int>>();
  26.  
  27.             int cnt = int.Parse(Console.ReadLine());
  28.  
  29.             for (int i = 0; i < cnt; i++)
  30.             {
  31.                 string[] input = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  32.                 string color = input[0];
  33.                 string clothes = input[1];
  34.                 string[] clothe = clothes.Split(',').ToArray();
  35.                 if (!wardrobe.ContainsKey(color))
  36.                 {
  37.                     wardrobe.Add(color, new Dictionary<string, int>());
  38.                 }
  39.                 for (int j = 0; j < clothe.Length; j++)
  40.                 {
  41.                     if (!wardrobe[color].ContainsKey(clothe[j]))
  42.                     {
  43.                         wardrobe[color].Add(clothe[j], 0);
  44.                     }
  45.                     wardrobe[color][clothe[j]] += 1;
  46.                 }        
  47.                
  48.             }
  49.             string[] search = Console.ReadLine().Split(' ').ToArray();
  50.             string searchedColor = search[0];
  51.             string searchedClothe = search[1];
  52.             foreach (KeyValuePair<string, Dictionary<string,int >> color in wardrobe)
  53.             {
  54.                 string printColor = color.Key;
  55.                 Dictionary<string, int> clothes = color.Value;
  56.  
  57.                 Console.WriteLine($"{printColor} clothes:");
  58.  
  59.                 foreach (KeyValuePair<string, int> clothe in clothes)
  60.                 {
  61.                     if (printColor == searchedColor && clothe.Key == searchedClothe)
  62.                     {
  63.                         Console.WriteLine($"* {clothe.Key} - {clothe.Value} (found!)");
  64.                     }
  65.                     else
  66.                     {
  67.                         Console.WriteLine($"* {clothe.Key} - {clothe.Value}");
  68.                     }                    
  69.                 }
  70.                
  71.             }
  72.  
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement