Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

razihanna avatar razihanna 7 Точки

3. Nikuldens meals C#

Hello,

I got 70/100 , any help to find my mistake

Thank you 

my code using System;using System.Collections.Generic;using System.Linq;namespac - Pastebin.com

 

Nikulden’s meals  Programming Fundamentals Final Exam - 07 December 2019 Group 2 - SoftUni Judge

Now you want to find out which meals your guests liked and how many meals they didn't like

Create a program that keeps information about guests liked and unliked meals.

You will be receiving lines with commands until you receive the "Stop" command. The possible commands are:

  • "Like-{guest}-{mea1}":
    • Add the {mea1} to the {guest}’s collection of meals.
    • If the guest doesn't exist, add it to your record.
    • If the guest already has the meal in his collection, don’t add it.
  • "Unlike-{guest}-{meal}":
    • Remove  the meal of the given guest’s collection and print:

"{Guest} doesn't like the {meal}."

You must keep the count of unliked meals!

  • If the guest doesn’t exist, print:

 "{Guest} is not at the party."

  • If the guest doesn’t have the meal at the like list, print:

 "{Guest} doesn't have the {meal} in his/her collection."

In the end, you have to print the guests with their liked meals sorted in descending order by each guest meals count and then by their names in ascending order. Then print the count of unliked meals in the format below

{Guest1}: {meal1}, {meal2}, {meal3}

{Guest2}: {meal1}, {meal2}

...

Unliked meals: {count of all unliked meals}

Input

  • You will be receiving lines until you receive the "Stop" command.
  • The input will always be valid.

Output

  • Print the guests with their meals in the format described above.
  • Print the count of unliked meals in the format described above.

 

 

 

 

Examples

Input

Output

Like-Krisi-shrimps

Like-Krisi-soup

Like-Misho-salad

Like-Pena-dessert

Stop

Krisi: shrimps, soup

Misho: salad

Pena: dessert

Unliked meals: 0

Input

Output

Like-Krisi-shrimps

Unlike-Vili-carp

Unlike-Krisi-salad

Unlike-Krisi-shrimps

Stop

Vili is not at the party.

Krisi doesn't have the salad in his/her collection.

Krisi doesn't like the shrimps.

Krisi:

Unliked meals: 1

Тагове:
0
Fundamentals Module
Axiomatik avatar Axiomatik 2422 Точки

Here's a solution for 100%, hope this helps.
 

Code:

using System;
using System.Linq;
using System.Collections.Generic;

namespace nikuldenMeal
{
    class Program
    {
        static void Main(string[] args)
        {
            var guestList = new Dictionary<string, List<string>>();

            string input = Console.ReadLine();

            int counterUnlike = 0;

            while (input != "Stop")
            {
                string[] inputSplit = input
                    .Split("-", StringSplitOptions.RemoveEmptyEntries);
                string action = inputSplit[0];
                string guest = inputSplit[1];
                string meal = inputSplit[2];

                if (action == "Like")
                {
                    if (!guestList.ContainsKey(guest))
                    {
                        guestList[guest] = new List<string>();
                        guestList[guest].Add(meal);
                    }
                    else if(!guestList[guest].Contains(meal))
                    {
                        guestList[guest].Add(meal);
                    }
                }
                else if (action == "Unlike")
                {
                    if (guestList.ContainsKey(guest))
                    {
                        if (guestList[guest].Contains(meal))
                        {
                            guestList[guest].Remove(meal);
                            Console.WriteLine($"{guest} doesn't like the {meal}.");
                            counterUnlike++;
                        }
                        else
                        {
                            Console.WriteLine($"{guest} doesn't have the {meal} in his/her collection.");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"{guest} is not at the party.");
                    }
                }

                input = Console.ReadLine();
            }


            foreach (var (guest, meals) in guestList.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
            {
                Console.WriteLine(guest + ": " + string.Join(", ", meals));
            }

            Console.WriteLine($"Unliked meals: {counterUnlike}");
        }
    }
}

 

1
razihanna avatar razihanna 7 Точки

Thank you verymuch

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