Advertisement
Guest User

Nikuldens Meal

a guest
Aug 6th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Nikulden_s_meals
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             int unlikedMeals = 0;
  13.  
  14.             Dictionary<string, List<string>> guests = new Dictionary<string, List<string>>();
  15.  
  16.             while (input!="Stop")
  17.             {
  18.                 var tokens = input.Split("-", StringSplitOptions.RemoveEmptyEntries);
  19.                 var command = tokens[0];
  20.  
  21.                 if (command=="Like")
  22.                 {
  23.                     var guestName = tokens[1];
  24.                     var meal = tokens[2];
  25.                     if (!guests.ContainsKey(guestName))
  26.                     {
  27.                         guests[guestName] = new List<string>();
  28.                     }
  29.                    
  30.                     if (!guests[guestName].Contains(meal))
  31.                     {
  32.                         guests[guestName].Add(meal);
  33.                     }
  34.                     else
  35.                     {
  36.                         continue;
  37.                     }
  38.                 }
  39.                 else if (command=="Unlike")
  40.                 {
  41.                     var guestName = tokens[1];
  42.                     var meal = tokens[2];
  43.                     if (!guests.ContainsKey(guestName))
  44.                     {
  45.                         Console.WriteLine($"{guestName} is not at the party.");
  46.                        
  47.                        
  48.                     }
  49.                     else if (!guests[guestName].Contains(meal))
  50.                     {
  51.                         Console.WriteLine($"{guestName} doesn't have the {meal} in his/her collection.");
  52.                     }
  53.                     else
  54.                     {
  55.                         guests[guestName].Remove(meal);
  56.                         Console.WriteLine($"{guestName} doesn't like the {meal}.");
  57.                         unlikedMeals++;
  58.                     }
  59.                                      
  60.                 }
  61.  
  62.                 input = Console.ReadLine();
  63.             }
  64.  
  65.             foreach (var guest in guests.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  66.             {
  67.                 Console.WriteLine($"{guest.Key}: {string.Join(", ",guest.Value)}");
  68.            
  69.             }
  70.             Console.WriteLine($"Unliked meals: {unlikedMeals}");
  71.         }
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement