Advertisement
viraco4a

2_Rainbow_Raindrops

Jan 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 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 RainbowRaindrop
  8. {
  9. class Raindrop : IComparable
  10. {
  11. public double Volume { get; set; }
  12. public int RedColorValue { get; set; }
  13. public int GreenColorValue { get; set; }
  14. public int BlueColorValue { get; set; }
  15.  
  16. public int CompareTo(object obj)
  17. {
  18. return Volume.CompareTo(obj);
  19. }
  20. }
  21.  
  22. class Program
  23. {
  24. static void Main(string[] args)
  25. {
  26. string input = Console.ReadLine();
  27. List<Raindrop> Rainbow = new List<Raindrop>();
  28. while (input != "End")
  29. {
  30. string[] SplittedInput = input.Split(' ').ToArray();
  31. if (SplittedInput.Length == 4)
  32. {
  33. Raindrop NewRaindrop = ExtractNewRaindrop(SplittedInput);
  34.  
  35. if (CheckForRainbowColors(NewRaindrop))
  36. {
  37. Rainbow.Add(NewRaindrop);
  38. }
  39. }
  40. input = Console.ReadLine();
  41. }
  42. List<Raindrop> OrderedRainbow = Rainbow.OrderBy(o => o.Volume).ToList();
  43. Console.WriteLine($"Rainbow Raindrops: {OrderedRainbow.Count}");
  44. if (OrderedRainbow.Count > 0)
  45. {
  46. for (int i = 0; i < OrderedRainbow.Count; i++)
  47. {
  48. double Volume = OrderedRainbow.ElementAt(i).Volume;
  49. int Red = OrderedRainbow.ElementAt(i).RedColorValue;
  50. int Green = OrderedRainbow.ElementAt(i).GreenColorValue;
  51. int Blue = OrderedRainbow.ElementAt(i).BlueColorValue;
  52.  
  53. Console.WriteLine($"{i + 1}. V:{Volume:f2} -> R:{Red} G:{Green} B:{Blue}");
  54. }
  55. }
  56. }
  57.  
  58. public static bool CheckForRainbowColors(Raindrop RaindropToCheck)
  59. {
  60. bool IsRainbow = false;
  61. if ((RaindropToCheck.RedColorValue > 200) && (RaindropToCheck.BlueColorValue < 100) && (RaindropToCheck.GreenColorValue < 100))
  62. {
  63. IsRainbow = true;
  64. }
  65. if ((RaindropToCheck.BlueColorValue > 200) && (RaindropToCheck.GreenColorValue < 100) && (RaindropToCheck.RedColorValue < 100))
  66. {
  67. IsRainbow = true;
  68. }
  69. if ((RaindropToCheck.GreenColorValue > 200) && (RaindropToCheck.RedColorValue < 100) && (RaindropToCheck.BlueColorValue < 100))
  70. {
  71. IsRainbow = true;
  72. }
  73.  
  74. return IsRainbow;
  75. }
  76.  
  77. private static Raindrop ExtractNewRaindrop(string[] SplittedInput)
  78. {
  79. int[] colorInfo = new int[3];
  80. for (int i = 1, j = 0; i < SplittedInput.Length; i++, j++)
  81. {
  82. colorInfo[j] = int.Parse(SplittedInput[i]);
  83. if (colorInfo[j] < 0 || colorInfo[j] > 255)
  84. {
  85. colorInfo[j] = 0;
  86. }
  87. }
  88.  
  89. Raindrop NewRaindrop = new Raindrop();
  90.  
  91. NewRaindrop.Volume = double.Parse(SplittedInput[0]);
  92. NewRaindrop.RedColorValue = colorInfo[0];
  93. NewRaindrop.GreenColorValue = colorInfo[1];
  94. NewRaindrop.BlueColorValue = colorInfo[2];
  95. return NewRaindrop;
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement