Advertisement
Guest User

odd even

a guest
Aug 26th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 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:0.##}, OddMin={1:0.##}, OddMax={2:0.##}, EvenSum=No, EvenMin=No, EvenMax=No", decimal.Parse(n[0]), decimal.Parse(n[0]), decimal.Parse(n[0]));
  29.          }
  30.          
  31.          else
  32.          {
  33.              for (int i = 0; i < n.Length; i++)
  34.              {
  35.                  if (i % 2 == 0)
  36.                  {
  37.                      oddArr.Add(decimal.Parse(n[i]));
  38.                  }
  39.                  else
  40.                  {
  41.                      evenArr.Add(decimal.Parse(n[i]));
  42.                  }
  43.              }
  44.              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());
  45.          }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement