Advertisement
dakata

Odd / Even Position

Oct 4th, 2016
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SimpleLoops
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11. #if DEBUG
  12.             Console.SetIn(new System.IO.StreamReader(@"E:\My Documents\Downloads\SoftUni\Input.txt"));
  13. #endif
  14.  
  15.             var n = int.Parse(Console.ReadLine());
  16.  
  17.             List<double> oddList = new List<double>();
  18.             List<double> evenList = new List<double>();
  19.  
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 var input = double.Parse(Console.ReadLine());
  23.  
  24.                 if (i%2 == 0) oddList.Add(input);
  25.                 else evenList.Add(input);
  26.             }
  27.  
  28.  
  29.             if (oddList.Count() == 0)
  30.             {
  31.                 Console.WriteLine("OddSum = {0}", 0);
  32.                 Console.WriteLine("OddMin = No");
  33.                 Console.WriteLine("OddMax = No");
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine($"OddSum = {oddList.Sum()}");
  38.                 Console.WriteLine($"OddMin = {oddList.Min()}");
  39.                 Console.WriteLine($"OddMax = {oddList.Max()}");
  40.             }
  41.  
  42.  
  43.             if (evenList.Count() == 0)
  44.             {
  45.                 Console.WriteLine("EvenSum = {0}", 0);
  46.                 Console.WriteLine("EvenMin = No");
  47.                 Console.WriteLine("EvenMax = No");
  48.             }
  49.             else
  50.             {
  51.                 Console.WriteLine($"EvenSum = {evenList.Sum()}");
  52.                 Console.WriteLine($"EvenMin = {evenList.Min()}");
  53.                 Console.WriteLine($"EvenMax = {evenList.Max()}");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement