Advertisement
Radost09

Condense Array to Number

Jan 25th, 2022
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P08_Condense_Array_to_Number
  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.             int[] condensed = new int[nums.Length - 1];
  15.            
  16.             if(nums.Length == 1)
  17.             {
  18.                 Console.WriteLine(nums[0]);
  19.                 return;
  20.             }
  21.             for (int i = 0; i < nums.Length; i++)
  22.             {
  23.                 for (int j = 0; j < condensed.Length - i; j++)
  24.                 {
  25.                     condensed[j] = nums[j] + nums[j + 1];
  26.                 }
  27.                 condensed = nums;
  28.             }
  29.             Console.WriteLine(condensed[0]);
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement