Advertisement
Guest User

FoldAndSum

a guest
Oct 4th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. public class AppendLists
  8. {
  9.     public static void Main()
  10.     {
  11.         var nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13.         int[] firstHalf = new int[nums.Length / 2];
  14.         int[] secondHalf = new int[nums.Length / 2];
  15.         int[] firstSum = new int[nums.Length / 2];
  16.         int[] secondSum = new int[nums.Length / 2];
  17.  
  18.         for (int i = 0; i < nums.Length / 2; i++)
  19.         {
  20.             firstHalf[i] = nums[i];
  21.         }
  22.         for (int i = 0; i < nums.Length / 2; i++)
  23.         {
  24.             secondHalf[i] = nums[nums.Length / 2 + i];
  25.         }
  26.         for (int i = 0; i < firstHalf.Length / 2; i++)
  27.         {
  28.             firstSum[i] = firstHalf[i] + firstHalf[firstHalf.Length - 1 - i];
  29.             secondSum[i] = secondHalf[i] + secondHalf[firstHalf.Length - 1 - i];
  30.         }
  31.  
  32.         int index = 0;
  33.         for (int i = firstSum.Length / 2; i < firstSum.Length; i++)
  34.         {
  35.             firstSum[i] = secondSum[index];
  36.             index++;
  37.         }
  38.  
  39.         Console.WriteLine(string.Join(" ", firstSum));
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement