zh_stoqnov

Odd Even Elements

Oct 28th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 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 Odd_Even_Elements
  8. {
  9. class OddEvenElements
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = Console.ReadLine();
  14. string[] elements = input.Split(' ');
  15. decimal oddSum = 0;
  16. decimal evenSum = 0;
  17. decimal oddMax = decimal.MinValue;
  18. decimal oddMin = decimal.MaxValue;
  19. decimal evenMax = decimal.MinValue;
  20. decimal evenMin = decimal.MaxValue;
  21. bool odd = true;
  22. if (input == "")
  23. {
  24. elements = new string[0];
  25. }
  26. for(int i = 0; i < elements.Length; i++)
  27. {
  28. decimal element = decimal.Parse(elements[i]);
  29. if(odd)
  30. {
  31. oddSum += element;
  32. oddMin = Math.Min(oddMin, element);
  33. oddMax = Math.Max(oddMax, element);
  34. }
  35. else
  36. {
  37. evenSum += element;
  38. evenMin = Math.Min(evenMin, element);
  39. evenMax = Math.Max(evenMax, element);
  40. }
  41. odd = !odd;
  42. }
  43. if(elements.Length == 0)
  44. {
  45. Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
  46. }
  47. else if (elements.Length == 1)
  48. {
  49. Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum=No, EvenMin=No, EvenMax=No", (double)oddSum, (double)oddMin, (double)oddMax);
  50. }
  51. else
  52. {
  53. Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum={3}, EvenMin={4}, EvenMax={5}", (double)oddSum, (double)oddMin, (double)oddMax, (double)evenSum, (double)evenMin, (double)evenMax);
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment