Advertisement
gadjov

Fold And Sum

Apr 6th, 2016
967
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 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. namespace FoldAndSum
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
  14.             int[] arrFoldA = new int[arr.Length / 2];
  15.             int[] arrFoldB = new int[arr.Length / 2];
  16.             int n = 0;
  17.             for (int i = arr.Length / 4 - 1; i >= 0; i--)
  18.             {
  19.                 arrFoldA[n] = arr[i];
  20.                 n++;
  21.             }
  22.             n = arr.Length / 2 - 1;
  23.             for (int i = arr.Length - arr.Length / 4; i < arr.Length; i++)
  24.             {
  25.                 arrFoldA[n] = arr[i];
  26.                 n--;
  27.             }
  28.             n = 0;
  29.             int start = arr.Length / 4;
  30.             int end = arr.Length - arr.Length / 4;
  31.             for (int i = start; i < end; i++)
  32.             {
  33.                 arrFoldB[n] = arr[i];
  34.                 n++;
  35.             }
  36.             int[] sum = new int[arrFoldA.Length];
  37.             for (int i = 0; i < arrFoldA.Length; i++)
  38.             {
  39.                 sum[i] = arrFoldA[i] + arrFoldB[i];
  40.             }
  41.             Console.WriteLine(string.Join(" ", sum));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement