-
Notifications
You must be signed in to change notification settings - Fork 1
/
OddEvenElements.cs
67 lines (65 loc) · 2.38 KB
/
OddEvenElements.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
class OddEvenElements
{
static void Main()
{
string input = Console.ReadLine();
string[] inputArray = input.Split(' ');
decimal oddSum = 0;
decimal oddMin = decimal.MaxValue;
decimal oddMax = decimal.MinValue;
decimal evenSum = 0;
decimal evenMin = decimal.MaxValue;
decimal evenMax = decimal.MinValue;
decimal number;
bool checkData = false;
for (int i = 1; i <= inputArray.Length; i++)
{
checkData = decimal.TryParse(inputArray[i - 1], out number);
if (i % 2 != 0)
{
oddSum += number;
if (number < oddMin)
{
oddMin = number;
}
if (number > oddMax)
{
oddMax = number;
}
}
if (i % 2 == 0)
{
evenSum += number;
if (number < evenMin)
{
evenMin = number;
}
if (number > evenMax)
{
evenMax = number;
}
}
}
if (checkData == true && oddMin != decimal.MaxValue && oddMax != decimal.MinValue && evenMin != decimal.MaxValue &&
evenMax != decimal.MinValue)
{
Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum={3}, EvenMin={4}, EvenMax={5}",
oddSum.ToString("G29"), oddMin.ToString("G29"), oddMax.ToString("G29"), evenSum.ToString("G29"), evenMin.ToString("G29"), evenMax.ToString("G29"));
}
else if (checkData == true && (oddMin == decimal.MaxValue || oddMax == decimal.MinValue))
{
Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum={1}, EvenMin={2}, EvenMax={3}",
evenSum.ToString("G29"), evenMin.ToString("G29"), evenMax.ToString("G29"));
}
else if (checkData == true && (evenMin == decimal.MaxValue || evenMax == decimal.MinValue))
{
Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum=No, EvenMin=No, EvenMax=No",
oddSum.ToString("G29"), oddMin.ToString("G29"), oddMax.ToString("G29"));
}
else
{
Console.WriteLine("OddSum=No, OddMin=No, OddMax=No, EvenSum=No, EvenMin=No, EvenMax=No");
}
}
}