Advertisement
Spocoman

08. Condense Array to Number

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