Advertisement
iskren_penev

FoldAndSum

May 12th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace FoldAndSum
  5. {
  6.     class FoldAndSum
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.             FoldItAndSumIt(input);
  12.         }
  13.         static void FoldItAndSumIt(int[] arr)
  14.         {
  15.             int k = arr.Length / 4;
  16.             int[] upper = new int[2 * k]; //upperRow
  17.             for (int i = 0; i < k; i++) //fill it
  18.             {
  19.                 upper[i] = arr[k - 1 - i];
  20.                 upper[k + i] = arr[4 * k - 1 - i]; //crazy math skill
  21.             }
  22.             int[] lower = new int[2 * k]; //lowerRow
  23.             for (int i = 0; i < 2 * k; i++) // fill it
  24.             {
  25.                 lower[i] = arr[k + i];
  26.             }
  27.             for (int i = 0; i < 2 * k; i++)
  28.             {
  29.                 //print the sum of the integers on each position
  30.                 Console.Write((lower[i] + upper[i]) + " ");
  31.             }
  32.             Console.WriteLine();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement