Advertisement
Guest User

OddEven

a guest
Jun 25th, 2015
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 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.  
  8. class OddEvenElements
  9. {
  10.     static void Main()
  11.     {
  12.         string input = Console.ReadLine();
  13.         string[] n = input.Split(' ');
  14.         List<decimal> oddArr = new List<decimal>{};
  15.         List<decimal> evenArr = new List<decimal> {};
  16.  
  17.         if (input == "")
  18.         {
  19.             // avoid runtime errors on the judge system
  20.             n = new string[0];
  21.         }
  22.          if (n.Length == 0)
  23.         {
  24.             Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
  25.         }
  26.          else if (n.Length == 1)
  27.          {
  28.              Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum=No, EvenMin=No, EvenMax=No", decimal.Parse(n[0]), decimal.Parse(n[0]), decimal.Parse(n[0]));
  29.          }
  30.          
  31.          else
  32.          {
  33.  
  34.              for (int i = 0; i < n.Length; i++)
  35.              {
  36.  
  37.                  if (i % 2 == 0)
  38.                  {
  39.                      oddArr.Add(decimal.Parse(n[i]));
  40.                  }
  41.                  else
  42.                  {
  43.                      evenArr.Add(decimal.Parse(n[i]));
  44.                  }
  45.              }
  46.              Console.WriteLine("OddSum={0:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum={3:0.##}, EvenMin={4:0.##}, EvenMax={5:0.##}", oddArr.Sum(), oddArr.Min(), oddArr.Max(), evenArr.Sum(), evenArr.Min(), evenArr.Max());
  47.          }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement