Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApplication.Random
  7. {
  8. class Region
  9. {
  10. public Region()
  11. {
  12. this.Roses = new List<Rose>();
  13. }
  14. public string Name { get; set; }
  15. public ICollection<Rose> Roses{ get; set; }
  16. public int TotalAmountOfRoses { get; set; }
  17. }
  18. class Rose
  19. {
  20. public string ColorName { get; set; }
  21. public int Amount { get; set; }
  22. }
  23.  
  24. class Program
  25. {
  26. static void Main(string[] args)
  27. {
  28. string input;
  29. var regions = new List<Region>();
  30. while((input = Console.ReadLine()) != "Icarus, Ignite!")
  31. {
  32. var info = input.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
  33. var regionName = info[1].Substring(1, info.Length - 2);
  34. var roseColor = info[2].Substring(1, info.Length - 2);
  35. var roseCount = int.Parse(info[3]);
  36.  
  37.  
  38.  
  39. var regionFromList = regions.FirstOrDefault(r => r.Name == regionName);
  40. if(regionFromList != null)
  41. {
  42. var roseFromRegion = regionFromList.Roses.FirstOrDefault(ro => ro.ColorName == roseColor);
  43. if(roseFromRegion != null)
  44. {
  45. roseFromRegion.Amount += roseCount;
  46. }
  47. else
  48. {
  49. regionFromList.Roses.Add(new Rose { ColorName = roseColor, Amount = roseCount });
  50. }
  51. }
  52. else
  53. {
  54. regions.Add(new Region { Name = regionName, Roses = new List<Rose>() { new Rose {ColorName = roseColor, Amount=roseCount } } });
  55. }
  56. }
  57.  
  58. foreach (var region in regions)
  59. {
  60. var totalAmount = 0;
  61. foreach (var rose in region.Roses)
  62. {
  63. totalAmount += rose.Amount;
  64. }
  65. region.TotalAmountOfRoses = totalAmount;
  66. }
  67. regions = regions.OrderByDescending(x => x.TotalAmountOfRoses).ThenBy(y => y.Name).ToList();
  68.  
  69. foreach (var region in regions)
  70. {
  71. region.Roses = region.Roses.OrderBy(x => x.Amount).ThenBy(y => y.ColorName).ToList();
  72. Console.WriteLine(region.Name);
  73. foreach (var rose in region.Roses)
  74. {
  75. Console.WriteLine($"*--{rose.ColorName} | {rose.Amount}");
  76. }
  77. }
  78. }
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement