-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pairs.cs
38 lines (36 loc) · 1016 Bytes
/
Pairs.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
using System;
class Pairs
{
static void Main()
{
string input = Console.ReadLine();
string[] numbers = input.Split(' ');
int sum = Convert.ToInt32(numbers[0]) + Convert.ToInt32(numbers[1]);
int maxDiff = int.MinValue;
int tempDiff = int.MinValue;
int tempSum = 0;
bool diffFound = false;
for (int i = 2; i < numbers.Length - 1; i += 2)
{
tempSum = Convert.ToInt32(numbers[i]) + Convert.ToInt32(numbers[i + 1]);
if (tempSum != sum)
{
diffFound = true;
tempDiff = Math.Abs(tempSum - sum);
sum = tempSum;
if (tempDiff > maxDiff)
{
maxDiff = tempDiff;
}
}
}
if (diffFound == false)
{
Console.WriteLine("Yes, value={0}", sum);
}
else
{
Console.WriteLine("No, maxdiff={0}", maxDiff);
}
}
}