Advertisement
bacco

Fold and Sum

Jun 1st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4.  
  5. namespace wew
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             int[] nums = Console.ReadLine()
  12.                                    .Split(' ')
  13.                                    .Select(int.Parse)
  14.                                    .ToArray();
  15.  
  16.             int k = nums.Length / 4;
  17.  
  18.             int[] upperLeft = new int[k];
  19.             int[] upperRight = new int[k];
  20.  
  21.             int[] upper = new int[k * 2];
  22.             int[] lower = new int[k * 2];
  23.  
  24.             for (int i = 0; i < k; i++)
  25.             {
  26.                 upperLeft[i]  = nums[i];
  27.                 upperRight[i] = nums[nums.Length - 1 - i];
  28.             }
  29.             Array.Reverse(upperLeft);
  30.  
  31.             for (int i = 0; i < k; i++)
  32.             {
  33.                 upper[i] = upperLeft[i];
  34.                 upper[i + k] = upperRight[i];
  35.             }
  36.            
  37.             for (int i = 0; i < k * 2; i++)
  38.             {
  39.                 lower[i] = nums[i + k];
  40.             }
  41.  
  42.             int[] sum = new int[k * 2];
  43.            
  44.             for (int i = 0; i < k * 2; i++)
  45.             {
  46.                 sum[i] = lower[i] + upper[i];
  47.             }
  48.  
  49.             Console.WriteLine(string.Join(" ", sum));
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement