Advertisement
silvana1303

hero recruitment

Aug 6th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6. using System.Data;
  7. using System.IO;
  8. using System.Reflection.PortableExecutable;
  9.  
  10. namespace _02._Boss_Rush
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             string[] command = Console.ReadLine().Split();
  17.  
  18.             Dictionary<string, List<string>> magic = new Dictionary<string, List<string>>();
  19.  
  20.             while (command[0] != "End")
  21.             {
  22.                 if (command[0] == "Enroll")
  23.                 {
  24.                     if (magic.ContainsKey(command[1]))
  25.                     {
  26.                         Console.WriteLine($"{command[1]} is already enrolled.");
  27.                     }
  28.                     else
  29.                     {
  30.                         magic[command[1]] = new List<string>();
  31.                     }
  32.                 }
  33.                 if (command[0] == "Learn")
  34.                 {
  35.                     if (magic.ContainsKey(command[1]))
  36.                     {
  37.                         bool spellExist = false;
  38.                         foreach (var item in magic)
  39.                         {
  40.                             if (item.Value.Contains(command[2]))
  41.                             {
  42.                                 spellExist = true;
  43.                             }
  44.                         }
  45.  
  46.                         if (spellExist)
  47.                         {
  48.                             Console.WriteLine($"{command[1]} has already learnt {command[2]}.");
  49.                         }
  50.                         else
  51.                         {
  52.                             magic[command[1]].Add(command[2]);
  53.                         }
  54.                     }
  55.                     else
  56.                     {
  57.                         Console.WriteLine($"{command[1]} doesn't exist.");
  58.                     }
  59.                 }
  60.                 if (command[0] == "Unlearn")
  61.                 {
  62.                     if (magic.ContainsKey(command[1]))
  63.                     {
  64.                         bool spellExist = false;
  65.                         foreach (var item in magic)
  66.                         {
  67.                             if (item.Value.Contains(command[2]))
  68.                             {
  69.                                 spellExist = true;
  70.                             }
  71.                         }
  72.  
  73.                         if (spellExist)
  74.                         {
  75.                             magic[command[1]].Remove(command[2]);
  76.                         }
  77.                         else
  78.                         {
  79.                             Console.WriteLine($"{command[1]} doesn't know {command[2]}.");
  80.                         }
  81.                     }
  82.                     else
  83.                     {
  84.                         Console.WriteLine($"{command[1]} doesn't exist.");
  85.                     }
  86.                 }
  87.  
  88.                 command = Console.ReadLine().Split();
  89.             }
  90.  
  91.             Console.WriteLine("Heroes:");
  92.             foreach (var item in magic.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  93.             {
  94.                 Console.WriteLine($"== {item.Key}: {string.Join(", ", item.Value)}");
  95.             }
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement