Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //On the first line of the input, you will receive n – the number of lines of clothes, which came prepackaged for the wardrobe.
- //On the next n lines, you will receive the clothes for each color in the format:
- //• “{color} -> {item1},{item2},{item3}…”
- //If a color is added a second time, add all items from it and count the duplicates.
- //Finally, you will receive the color and item of the clothing, that you need to look for.
- //Output
- //Go through all the colors of the clothes and print them in the following format:
- //{color} clothes:
- //* {item1} - {count}
- //* {item2} - {count}
- //* {item3} - {count}
- //If the color lines up with the clothing item, print “(found!)” alongside the item. See the examples to better understand the output.
- namespace Wardrobe
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> wardrobe = new Dictionary<string, Dictionary<string, int>>();
- int cnt = int.Parse(Console.ReadLine());
- for (int i = 0; i < cnt; i++)
- {
- string[] input = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string color = input[0];
- string clothes = input[1];
- string[] clothe = clothes.Split(',').ToArray();
- if (!wardrobe.ContainsKey(color))
- {
- wardrobe.Add(color, new Dictionary<string, int>());
- }
- for (int j = 0; j < clothe.Length; j++)
- {
- if (!wardrobe[color].ContainsKey(clothe[j]))
- {
- wardrobe[color].Add(clothe[j], 0);
- }
- wardrobe[color][clothe[j]] += 1;
- }
- }
- string[] search = Console.ReadLine().Split(' ').ToArray();
- string searchedColor = search[0];
- string searchedClothe = search[1];
- foreach (KeyValuePair<string, Dictionary<string,int >> color in wardrobe)
- {
- string printColor = color.Key;
- Dictionary<string, int> clothes = color.Value;
- Console.WriteLine($"{printColor} clothes:");
- foreach (KeyValuePair<string, int> clothe in clothes)
- {
- if (printColor == searchedColor && clothe.Key == searchedClothe)
- {
- Console.WriteLine($"* {clothe.Key} - {clothe.Value} (found!)");
- }
- else
- {
- Console.WriteLine($"* {clothe.Key} - {clothe.Value}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement