tanya_zheleva

Condence

Jan 30th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] numbers = Console.ReadLine()
  11.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             while (numbers.Length > 1)
  16.             {
  17.                 int[] condensed = new int[numbers.Length - 1];
  18.  
  19.                 for (int i = 0; i < numbers.Length - 1; i++)
  20.                 {
  21.                     condensed[i] = numbers[i] + numbers[i + 1];
  22.                 }
  23.  
  24.                 numbers = condensed;
  25.             }
  26.  
  27.             Console.WriteLine(numbers[0]);
  28.         }
  29.     }
  30. }
Add Comment
Please, Sign In to add comment