Advertisement
milislavski

EvenDifferences

May 9th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. namespace Problem2
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     class EvenDifferences
  7.     {
  8.         static void Main()
  9.         {
  10.             string[] input = Console.ReadLine().Split(' ');
  11.             long[] numbers = new long[input.Length];
  12.             for (int i = 0; i < input.Length; i++)
  13.             {
  14.                 numbers[i] = long.Parse(input[i]);
  15.             }
  16.  
  17.            
  18.            
  19.             long sumOfEven = 0;
  20.  
  21.             for (int i = 1; i < numbers.Length; i++)
  22.             {
  23.                 long absDifference = Math.Abs(numbers[i-1]-numbers[i]);
  24.                 if (absDifference % 2 == 0)
  25.                 {
  26.                     i++;
  27.                     sumOfEven += absDifference;
  28.                    
  29.                 }
  30.  
  31.                
  32.             }
  33.  
  34.             Console.WriteLine(sumOfEven);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement