Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
102
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 DictMoreExc4
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var dwarfs = new Dictionary<string, Dictionary<string, int>>();
  14. var sortedDwarfs = new Dictionary<string, int>();
  15. while (true)
  16. {
  17. string command = Console.ReadLine();
  18. if (command == "Once upon a time")
  19. {
  20. foreach (var hatcolor in dwarfs.OrderByDescending(x => x.Value.Count()))
  21. {
  22. foreach (var dwarf in hatcolor.Value)
  23. {
  24. sortedDwarfs.Add($"({hatcolor.Key}) {dwarf.Key} <-> ", dwarf.Value);
  25. }
  26. }
  27. foreach (var item in sortedDwarfs.OrderByDescending(x => x.Value))
  28. {
  29. Console.WriteLine(item.Key + item.Value);
  30. }
  31. break;
  32. }
  33. var split = command.Split(new string[] { " <:> " }, StringSplitOptions.None).ToList();
  34. string DwarfName = split[0];
  35. string DwarfColor = split[1];
  36. int DwarfPoints = int.Parse(split[2]);
  37. if (!dwarfs.ContainsKey(DwarfColor))
  38. {
  39. dwarfs.Add(DwarfColor, new Dictionary<string, int>());
  40. dwarfs[DwarfColor].Add(DwarfName, DwarfPoints);
  41.  
  42. }
  43. else if (dwarfs.ContainsKey(DwarfColor))
  44. {
  45. if (!dwarfs[DwarfColor].ContainsKey(DwarfName))
  46. {
  47. dwarfs[DwarfColor].Add(DwarfName, DwarfPoints);
  48. }
  49. else
  50. {
  51. if (dwarfs[DwarfColor][DwarfName] < DwarfPoints)
  52. {
  53. dwarfs[DwarfColor][DwarfName] = DwarfPoints;
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement