Advertisement
AdelinaMladenova

CondenseArrayToNumber

Jul 6th, 2019
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _7.CondenseArrayToNumber
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine()
  11.                           .Split()
  12.                           .Select(int.Parse)
  13.                           .ToArray();
  14.            
  15.             if (arr.Length == 1)
  16.             {
  17.                 Console.WriteLine(arr[0]);
  18.                 return;
  19.             }
  20.             else
  21.             {
  22.                 while (arr.Length != 1)
  23.                 {
  24.                     int[] condensed = new int[arr.Length - 1];
  25.                     for (int i = 0; i < arr.Length-1; i++)
  26.                     {
  27.                         condensed[i] = arr[i] + arr[i + 1];
  28.                     }
  29.                     arr = condensed;
  30.  
  31.                 }
  32.                
  33.                 Console.WriteLine(arr[0]);
  34.             }      
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement