Advertisement
silvana1303

nikulden's meals

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