Exercises: Sets and Dictionaries Advanced, Problem 6. Wardrobe
only 60 from 100 points.
(поне при сравняване на око, отговорите ми на дадените примери са верни)
Problem 6. Wardrobe
Write a program that helps you decide what clothes to wear from your wardrobe. You will receive the clothes,
which are currently in your wardrobe, sorted by their color in the following format:
"{color} -> {item1},{item2},{item3}…"
If you receive a certain color, which already exists in your wardrobe, just add the clothes to its records. You can also
receive repeating items for a certain color and you have to keep their count.
In the end, you will receive a color and a piece of clothing, which you will look for in the wardrobe, separated by a
space in the following format:
"{color} {clothing}"
Your task is to print all the items and their count for each color in the following format:
"{color} clothes:
* {item1} - {count}
* {item2} - {count}
* {item3} - {count}
…
* {itemN} - {count}"
If you find the item you are looking for, you need to print "(found!)" next to it:
"* {itemN} - {count} (found!)"
Input
On the first line, you will receive n – the number of lines of clothes, which you will receive.
On the next n lines, you will receive the clothes in the format described above.
Output
Print the clothes from your wardrobe in the format described above.
Examples
Input
4
Blue -> dress,jeans,hat
Gold -> dress,t-shirt,boxers
White -> briefs,tanktop
Blue -> gloves
Output
Blue clothes:
* dress - 1 (found!)
* jeans - 1
* hat - 1
* gloves - 1
Blue dress Gold clothes:
* dress - 1
* t-shirt - 1
* boxers - 1
White clothes:
* briefs - 1
* tanktop - 1
input
4
Red -> hat
Red -> dress,t-shirt,boxers
White -> briefs,tanktop
Blue -> gloves
White tanktop
output
Red clothes:
* hat - 1
* dress - 1
* t-shirt - 1
* boxers - 1
White clothes:
* briefs - 1
* tanktop - 1 (found!)
Blue clothes:
* gloves - 1
input
5
Blue -> shoes
Blue -> shoes,shoes,shoes
Blue -> shoes,shoes
Blue -> shoes
Blue -> shoes,shoes
Red tanktop
output
Blue clothes:
* shoes - 9
My Cod
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var wardrobe = new Dictionary<string, Dictionary<string, int>>();
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
string[] inputPrim = Console.ReadLine()
.Split();
string collor = inputPrim[0];
string[] clothes = GetStringArray(inputPrim[2], new char[]{','});
if(!wardrobe.ContainsKey(collor))
{
wardrobe[collor] = new Dictionary<string, int>();
}
for (int c = 0; c < clothes.Length; c++)
{
if(!wardrobe[collor].ContainsKey(clothes[c]))
{
wardrobe[collor][clothes[c]] = 0;
}
wardrobe[collor][clothes[c]]++;
} // end internal for
} // end external for
// Part II
string[] command = GetStringArray(Console.ReadLine(), new char[]{' '});
string needCollor = command[0];
string needClothes = command[1];
// Part III
foreach (var currentCollor in wardrobe)
{
Console.WriteLine("{0} clothes:", currentCollor.Key);
Dictionary<string, int> collorsClothes = currentCollor.Value;
foreach (var currentCloth in collorsClothes)
{
Console.Write("* {0} - {1}", currentCloth.Key, currentCloth.Value);
if (currentCollor.Key == needCollor && currentCloth.Key == needClothes)
{
Console.Write(" (found!)");
}
Console.WriteLine();
}
}
}
public static string[] GetStringArray(string input, params char[] simbols)
{
return input
.Split(simbols, StringSplitOptions.RemoveEmptyEntries)
.ToArray();
}
}
/*
4
Blue -> dress,jeans,hat
Gold -> dress,t-shirt,boxers
White -> briefs,tanktop
Blue -> gloves
Blue dress
Blue clothes:
* dress - 1 (found!)
* jeans - 1
* hat - 1
* gloves - 1
Gold clothes:
* dress - 1
* t-shirt - 1
* boxers - 1
White clothes:
* briefs - 1
* tanktop - 1
II example
4
Red -> hat
Red -> dress,t-shirt,boxers
White -> briefs,tanktop
Blue -> gloves
White tanktop
Red clothes:
* hat - 1
* dress - 1
* t-shirt - 1
* boxers - 1
White clothes:
* briefs - 1
* tanktop - 1 (found!)
Blue clothes:
* gloves - 1
III example
5
Blue -> shoes
Blue -> shoes,shoes,shoes
Blue -> shoes,shoes
Blue -> shoes
Blue -> shoes,shoes
Red tanktop
*/