zaryana

CondenseArrayToNumber

Feb 3rd, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 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 CondenseArrayToNum
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] arr = Console.ReadLine()
  14.                .Split()
  15.                .Select(int.Parse)
  16.                .ToArray();
  17.             int[] condArr = new int[arr.Length - 1];
  18.  
  19.             if (arr.Length == 1)
  20.             {
  21.                 Console.WriteLine(arr[0]);
  22.             }
  23.             else if (arr.Length > 1)
  24.             {
  25.             for (int i = 0; i < arr.Length; i++)
  26.             {
  27.                 for (int j = 0; j < condArr.Length - i; j++)
  28.                 {
  29.                     condArr[j] = arr[j] + arr[j + 1];
  30.                 }
  31.                 arr = condArr;
  32.             }
  33.             Console.WriteLine(condArr[0]);
  34.             }
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment