Advertisement
Alexander_B

Odd / Even Position

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