tanya_zheleva

03

Jan 31st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Startup
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] numbers = Console.ReadLine()
  12.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(x => int.Parse(x))
  14.                 .ToArray();
  15.             int k = numbers.Length/4;
  16.  
  17.             IEnumerable<int> firstPart = numbers.Take(k).Reverse();
  18.             IEnumerable<int> lastPart = numbers.Skip(3 * k).Reverse();
  19.  
  20.             int[] firstHalf = firstPart.Concat(lastPart).ToArray();
  21.             int[] middlePart = numbers.Skip(k).Take(2 * k).ToArray();
  22.  
  23.             IEnumerable<int> folded = firstHalf.Select((number, index) => number += middlePart[index]);
  24.  
  25.             Console.WriteLine(string.Join(" ", folded));
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment