bullit3189

Snowwhite - Dictionaries

Jan 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Snowwhite
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var dwarfs = new Dictionary<string, int>();
  12. string input = Console.ReadLine();
  13. while (input != "Once upon a time")
  14. {
  15. string[] inputs = input.Split(new string[] { " <:> " }, StringSplitOptions.None);
  16. string name = inputs[0];
  17. string color = inputs[1];
  18. int physics = int.Parse(inputs[2]);
  19.  
  20. string ID = name + ":" + color;
  21. if (!dwarfs.ContainsKey(ID))
  22. {
  23. dwarfs.Add(ID, physics);
  24. }
  25. else
  26. {
  27. dwarfs[ID] = Math.Max(dwarfs[ID], physics);
  28. }
  29.  
  30. input = Console.ReadLine();
  31. }
  32. foreach (var dwarf in dwarfs
  33. .OrderByDescending(x => x.Value)
  34. .ThenByDescending(x => dwarfs.Where(y => y.Key.Split(':')[1] == x.Key.Split(':')[1])
  35. .Count()))
  36. {
  37. Console.WriteLine("({0}) {1} <-> {2}",
  38. dwarf.Key.Split(':')[1],
  39. dwarf.Key.Split(':')[0],
  40. dwarf.Value);
  41. }
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment