Loading...
anton_fotev avatar anton_fotev 9 Точки

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


*/

 

Тагове:
0
C# Advanced
sarathsri avatar sarathsri -3 Точки

I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done. <a href="https://bestphptraininginchennai.in/">PHP Training in Chennai</a> | <a href="https://bestphptraininginchennai.in/">Best PHP Training Institute in Chennai</a>

-1
sarathsri avatar sarathsri -3 Точки

I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done. PHP Training in Chennai

-1
sarathsri avatar sarathsri -3 Точки

I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done. PHP Training in Chennai

-1
softlogic avatar softlogic -1 Точки

Thanks for sharing such a helpful information. I really enjoyed reading it.

Add a competitive advantage to your portfolio with us! We offer you extensive training with the best AWS training in Chennai along with placement assistance from our highly trained instructors. Together, let's work! We can assist you in advancing your career. Get comprehensive hands-on AWS training that is specially created to help you build a career in cloud computing technology while developing your knowledge and skills. In Chennai, SLA offers the top AWS training and job placement services. To succeed in your AWS career, get in touch!

Java Training in Chennai

Data Science Course in Chennai

-1
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.