deleriumbg

Fold and Sum

Apr 21st, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Fold_and_Sum
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
  12.             int size = input.Count / 4;
  13.             List<int> topLeft = new List<int>();
  14.             List<int> topRight = new List<int>();
  15.             List<int> top = new List<int>();
  16.             List<int> bottom = new List<int>();
  17.             topLeft.AddRange(input.Take(size));
  18.             topLeft.Reverse();
  19.             input.Reverse();
  20.             topRight.AddRange(input.Take(size));
  21.             input.Reverse();
  22.             bottom.AddRange(input.Skip(size).Take(size * 2));
  23.             top.AddRange(topLeft.Concat(topRight));
  24.  
  25.             var sum = top.Select((x, index) => x + bottom[index]);
  26.             Console.WriteLine(string.Join(" ", sum));
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment