Advertisement
viraco4a

EvenODD

Mar 2nd, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 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 _11_OddEvenPosition
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. double oddMin = double.MaxValue;
  15. double oddMax = double.MinValue;
  16. double oddSum = 0;
  17. double evenMin = double.MaxValue;
  18. double evenMax = double.MinValue;
  19. double evenSum = 0;
  20. Calc(n, ref oddMin, ref oddMax, ref oddSum, ref evenMin, ref evenMax, ref evenSum);
  21.  
  22. PrintOdd(oddMin, oddMax, oddSum);
  23. PrintEven(evenMin, evenMax, evenSum);
  24.  
  25. }
  26.  
  27. private static void PrintEven(double evenMin, double oddMax, double evenSum)
  28. {
  29. Console.WriteLine($"EvenSum={evenSum},");
  30. if (evenMin < double.MaxValue)
  31. {
  32. Console.WriteLine($"EvenMin={evenMin},");
  33. }
  34. else
  35. {
  36. Console.WriteLine("EvenMin=No,");
  37. }
  38. if (oddMax > double.MinValue)
  39. {
  40. Console.WriteLine($"EvenMax={oddMax},");
  41. }
  42. else
  43. {
  44. Console.WriteLine("EvenMax=No,");
  45. }
  46. }
  47.  
  48. private static void PrintOdd(double oddMin, double oddMax, double oddSum)
  49. {
  50. Console.WriteLine($"OddSum={oddSum},");
  51. if (oddMin < double.MaxValue)
  52. {
  53. Console.WriteLine($"OddMin={oddMin},");
  54. }
  55. else
  56. {
  57. Console.WriteLine("OddMin=No,");
  58. }
  59. if (oddMax > double.MinValue)
  60. {
  61. Console.WriteLine($"OddMax={oddMax},");
  62. }
  63. else
  64. {
  65. Console.WriteLine("OddMax=No,");
  66. }
  67. }
  68.  
  69. private static void Calc(int n, ref double oddMin, ref double oddMax, ref double oddSum, ref double evenMin, ref double evenMax, ref double evenSum)
  70. {
  71. for (int i = 1; i <= n; i++)
  72. {
  73. double num = double.Parse(Console.ReadLine());
  74. if (i % 2 != 0)
  75. {
  76. oddSum += num;
  77. if (num > oddMax)
  78. {
  79. oddMax = num;
  80. }
  81. if (num < oddMin)
  82. {
  83. oddMin = num;
  84. }
  85. }
  86. else
  87. {
  88. evenSum += num;
  89. if (num > evenMax)
  90. {
  91. evenMax = num;
  92. }
  93. if (num < evenMin)
  94. {
  95. evenMin = num;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement