Advertisement
DeeAG

04.FoldAndSum

Feb 26th, 2021
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _04.FoldAndSum
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine()
  11.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             int foldPoint = arr.Length / 2 / 2;
  16.  
  17.             int[] resultArr = new int[foldPoint * 2];
  18.  
  19.             for (int i = 0; i < foldPoint; i++)
  20.             {
  21.                 resultArr[i] = arr[i + foldPoint] + arr[foldPoint - 1 - i];
  22.  
  23.                 resultArr[i + foldPoint] = arr[i + 2 * foldPoint] + arr[arr.Length - 1 - i];
  24.  
  25.             }
  26.  
  27.             Console.WriteLine(String.Join(' ', resultArr));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement