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;
- namespace _01NestedDictionariesExcercisesWardrobe
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> clothes = new Dictionary<string, Dictionary<string, int>>();
- int num = int.Parse(Console.ReadLine());
- for (int i = 0; i < num; i++)
- {
- string[] inputTokens = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string color = inputTokens[0];
- string[] allDresses = inputTokens[1].Split(',').ToArray();
- string cloth = string.Empty;
- for (int j =0; j <allDresses.Length; j++)
- {
- cloth = allDresses[j];
- if (!clothes.ContainsKey(color))
- {
- clothes.Add(color, new Dictionary<string, int>());
- clothes[color].Add(cloth, 1);
- }
- else
- {
- if(!clothes[color].ContainsKey(cloth))
- {
- clothes[color].Add(cloth, 1);
- }
- else
- {
- clothes[color][cloth] ++;
- }
- }
- }
- }
- // input and filling the data done :D if proverkite neshto gurmqt
- string[] marker = Console.ReadLine().Split(' ').ToArray();
- string markerColor = marker[0];
- string markerCloth = marker[1];
- foreach (KeyValuePair<string,Dictionary<string,int>> pair in clothes)
- {
- string colour = pair.Key;
- Console.WriteLine($"{colour} clothes:");
- Dictionary<string, int> wardrobeclothes = pair.Value;
- foreach(KeyValuePair<string,int>kvp in wardrobeclothes)
- {
- string dress = kvp.Key;
- int count = kvp.Value;
- if(colour==markerColor && dress==markerCloth)
- {
- Console.WriteLine($"* {dress} - {count} (found!)");
- }
- else
- {
- Console.WriteLine($"* {dress} - {count}");
- }
- }
- }
- //output-a raboti samo logikata da oprava
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment