Advertisement
n4wn4w

2zadacha6variant

Mar 17th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             //   System.Threading.Thread.CurrentThread.CurrentCulture =
  13.             //  System.Globalization.CultureInfo.InvariantCulture;
  14.  
  15.             //string input = Console.ReadLine();
  16.  
  17.             string[] inputNumbers = Console.ReadLine().Split(new string[] { " " },
  18.                      StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.             decimal oddSum = 0m;// za decimal
  21.             decimal oddMin = decimal.MaxValue;
  22.             decimal oddMax = decimal.MinValue;
  23.             decimal evenSum = 0m;
  24.             decimal evenMin = decimal.MaxValue;
  25.             decimal evenMax = decimal.MinValue;
  26.  
  27.  
  28.             for (int i = 0; i < inputNumbers.Length; i++)
  29.             {
  30.                 decimal element = decimal.Parse(inputNumbers[i]);
  31.                 if (i % 2 == 0)   // tuk e ODD zashtoto sme v masiv i po4va ot indeks 0 1 2 3 4 5
  32.                 {                 // i realno po4vame ot 0 koeto e EVEN 2 4 6 8
  33.                     oddSum = oddSum + element;
  34.                     oddMin = Math.Min(oddMin, element);
  35.                     oddMax = Math.Max(oddMax, element);
  36.                 }
  37.                 else
  38.                 {
  39.                     evenSum = evenSum + element;
  40.                     evenMin = Math.Min(evenMin, element);
  41.                     evenMax = Math.Max(evenMax, element);
  42.                 }
  43.  
  44.             }
  45.  
  46.             if (inputNumbers.Length == 0)
  47.             {
  48.                 Console.WriteLine(
  49.                     "OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
  50.             }
  51.             else if (inputNumbers.Length == 1)
  52.             {
  53.                 Console.WriteLine(
  54.                     "OddSum={0}, OddMin={1}, OddMax={2}, EvenSum=No, EvenMin=No, EvenMax=No",
  55.                     (double)oddSum, (double)oddMin, (double)oddMax);
  56.             }
  57.             else
  58.             {
  59.                 Console.WriteLine(
  60.                     "OddSum={0}, OddMin={1}, OddMax={2}, EvenSum={3}, EvenMin={4}, EvenMax={5}",
  61.                     (double)oddSum, (double)oddMin, (double)oddMax,
  62.                     (double)evenSum, (double)evenMin, (double)evenMax);
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement