kirililchev3

Condense Array to Number

Jun 3rd, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. namespace Condense_Array_to_Number
  2. {
  3.     using System;
  4.  
  5.     public class Condense_Array_to_Number
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string[] numbers = Console.ReadLine().Split();
  10.             int[] nums = new int[numbers.Length];
  11.             for (int i = 0; i < nums.Length; i++)
  12.             {
  13.                 nums[i] = int.Parse(numbers[i]);
  14.             }
  15.  
  16.             if (nums.Length == 1)
  17.             {
  18.                 Console.WriteLine($"{nums[0]} is already condensed to number");
  19.             }
  20.             else
  21.             {
  22.                 while (true)
  23.                 {
  24.                     int[] sums = new int[nums.Length - 1];
  25.                     for (int i = 0; i < nums.Length - 1; i++)
  26.                     {
  27.                         sums[i] = nums[i] + nums[i + 1];
  28.                     }
  29.  
  30.                     nums = sums;
  31.  
  32.                     if (nums.Length == 1)
  33.                     {
  34.                         Console.WriteLine(nums[0]);
  35.                         break;
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment