Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03._Nikulden_s_meals
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- int unlikedMeals = 0;
- Dictionary<string, List<string>> guests = new Dictionary<string, List<string>>();
- while (input!="Stop")
- {
- var tokens = input.Split("-", StringSplitOptions.RemoveEmptyEntries);
- var command = tokens[0];
- if (command=="Like")
- {
- var guestName = tokens[1];
- var meal = tokens[2];
- if (!guests.ContainsKey(guestName))
- {
- guests[guestName] = new List<string>();
- }
- if (!guests[guestName].Contains(meal))
- {
- guests[guestName].Add(meal);
- }
- else
- {
- continue;
- }
- }
- else if (command=="Unlike")
- {
- var guestName = tokens[1];
- var meal = tokens[2];
- if (!guests.ContainsKey(guestName))
- {
- Console.WriteLine($"{guestName} is not at the party.");
- }
- else if (!guests[guestName].Contains(meal))
- {
- Console.WriteLine($"{guestName} doesn't have the {meal} in his/her collection.");
- }
- else
- {
- guests[guestName].Remove(meal);
- Console.WriteLine($"{guestName} doesn't like the {meal}.");
- unlikedMeals++;
- }
- }
- input = Console.ReadLine();
- }
- foreach (var guest in guests.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{guest.Key}: {string.Join(", ",guest.Value)}");
- }
- Console.WriteLine($"Unliked meals: {unlikedMeals}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement