Advertisement
sivancheva

TrophonTheGrumpyCat

Oct 5th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 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 _02_TrophonTheGrumpyCat
  8. {
  9. class TrophonTheGrumpyCat
  10. {
  11. static void Main(string[] args)
  12. {
  13. var input = Console.ReadLine();
  14. var inputArray = input.Split(' ').Select(long.Parse).ToArray();
  15. int index = int.Parse(Console.ReadLine());
  16. var middleElement = inputArray[index];
  17.  
  18. var command = Console.ReadLine();
  19. var priceRating = Console.ReadLine();
  20.  
  21. var leftArr = new List<long>(inputArray);
  22. leftArr.RemoveRange((index), (inputArray.Length - (index)));
  23. long leftSum = 0;
  24.  
  25. var rightArr = new List<long>(inputArray);
  26. rightArr.RemoveRange(0, (index+1));
  27. long rightSum = 0;
  28.  
  29. if (command == "cheap")
  30. {
  31. if (priceRating == "positive")
  32. {
  33. leftSum = leftArr.Where(x => x < middleElement && x > 0).Sum();
  34. rightSum = rightArr.Where(x => x < middleElement && x > 0).Sum();
  35. }
  36. else if (priceRating == "negative")
  37. {
  38. leftSum = leftArr.Where(x => x < middleElement && x < 0).Sum();
  39. rightSum = rightArr.Where(x => x < middleElement && x < 0).Sum();
  40. }
  41. else
  42. {
  43. leftSum = leftArr.Where(x => x < middleElement).Sum();
  44. rightSum = rightArr.Where(x => x < middleElement).Sum();
  45. }
  46. }
  47. else if (command == "expensive")
  48. {
  49. if (priceRating == "positive")
  50. {
  51. leftSum = leftArr.Where(x => x >= middleElement && x > 0).Sum();
  52. rightSum = rightArr.Where(x => x >= middleElement && x > 0).Sum();
  53. }
  54. else if (priceRating == "negative")
  55. {
  56. leftSum = leftArr.Where(x => x >= middleElement && x < 0).Sum();
  57. rightSum = rightArr.Where(x => x >= middleElement && x < 0).Sum();
  58. }
  59. else
  60. {
  61. leftSum = leftArr.Where(x => x >= middleElement).Sum();
  62. rightSum = rightArr.Where(x => x >= middleElement).Sum();
  63. }
  64. }
  65.  
  66. if (leftSum >= rightSum)
  67. {
  68. Console.WriteLine($"Left - {leftSum}");
  69. }
  70. else if (leftSum < rightSum)
  71. {
  72. Console.WriteLine($"Right - {rightSum}");
  73. }
  74.  
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement