Viacheslav

TelerikAlphaExamOctober11Problem03CrookedWalls

Oct 12th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Problem04
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             long[] wallHeight = Console.ReadLine().Split(new char[] { ' ' },
  11.                                                      StringSplitOptions
  12.                                                      .RemoveEmptyEntries)
  13.                                        .Select(long.Parse).ToArray();
  14.             List<long> wallDiff = new List<long>();
  15.             for (int i = 1; i < wallHeight.Length; i++)
  16.             {
  17.                 long wallABS = Math.Abs(wallHeight[i] - wallHeight[i - 1]) ;
  18.                 if (wallDiff.Count < 1 || wallDiff[i - 2] == 0)
  19.                 {
  20.                     wallDiff.Add(wallABS);
  21.                 }
  22.                 else
  23.                 {
  24.                     if (wallDiff[i - 2] % 2 == 0)
  25.                     {
  26.                         wallDiff.Add(0);
  27.                     }
  28.                     else
  29.                     {
  30.                         wallDiff.Add(wallABS);
  31.                     }
  32.                 }
  33.             }
  34.             long sum = 0;
  35.             for (int i = 0; i < wallDiff.Count; i++)
  36.             {
  37.                 if (wallDiff[i] % 2 == 0)
  38.                 {
  39.                     sum += wallDiff[i];
  40.                 }
  41.             }
  42.             Console.WriteLine(string.Join(" ", sum));
  43.  
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment