Advertisement
Guest User

Resize array

a guest
May 27th, 2016
137
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CondenseArrayToNumber
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.  
  15.             while (nums.Length != 1)
  16.             {
  17.                 for (int i = 0; i < nums.Length - 1; i++)
  18.                 {
  19.                     nums[i] = nums[i] + nums[i + 1];
  20.                 }
  21.                 Array.Resize( ref nums, nums.Length - 1);
  22.             }
  23.             Console.WriteLine(nums[0]);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement