Advertisement
sivancheva

Phoenix Oscar Romeo November

Oct 25th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04_PhoenixOscarRomeoNovember
  8. {
  9. class PhoenixOscarRomeoNovember
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14. var input = Console.ReadLine();
  15. var result = new Dictionary<string, List<string>>();
  16.  
  17.  
  18. while (input != "Blaze it!")
  19. {
  20. var inputArr = input.Split(new string[] { "->"}, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
  21.  
  22. if (inputArr.Length != 2)
  23. {
  24. input = Console.ReadLine();
  25. }
  26. string creature = inputArr[0];
  27. string squadMate = inputArr[1];
  28.  
  29. if (!result.ContainsKey(creature))
  30. {
  31. result.Add(creature, new List<string>());
  32. result[creature].Add(squadMate);
  33. }
  34. else if (!result[creature].Contains(squadMate))
  35. {
  36. result[creature].Add(squadMate);
  37. }
  38.  
  39. input = Console.ReadLine();
  40. }
  41.  
  42. var modifiedResultDict = new Dictionary<string, List<string>>();
  43.  
  44. foreach (var pair in result)
  45. {
  46. modifiedResultDict.Add(pair.Key, new List<string>());
  47. modifiedResultDict[pair.Key].AddRange(pair.Value);
  48. }
  49.  
  50. foreach (var creature in result)
  51. {
  52. var nameCreature = creature.Key;
  53.  
  54. foreach (var squardMate in creature.Value.ToList())
  55. {
  56. if (result.Keys.Any(x => x.Equals(squardMate)) && result[squardMate].Contains(nameCreature) )
  57. {
  58. modifiedResultDict[nameCreature].Remove(squardMate);
  59. }
  60. }
  61. }
  62.  
  63. foreach (var a in modifiedResultDict.OrderByDescending(x => x.Value.Count))
  64. {
  65. Console.WriteLine($"{a.Key} : {a.Value.Count}");
  66. }
  67.  
  68.  
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement