Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Fold_and_Sum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int k = arr.Length / 4;
- int[] midArr = new int[2 * k];
- int[] upperArr1 = new int[k];
- int[] upperArr2 = new int[k];
- int[] sumArr = new int[2 * k];
- // defining the lower row
- for (int i = 0; i < 2 * k; i++)
- {
- midArr[i] = arr[i + k];
- }
- //defining the upper row
- //first half
- for (int i = 0; i < k; i++)
- {
- upperArr1[i] = arr[i];
- }
- upperArr1 = upperArr1.Reverse().ToArray();
- // second half
- for (int i = 0; i < k; i++)
- {
- upperArr2[i] = arr[3 * k + i];
- }
- upperArr2 = upperArr2.Reverse().ToArray();
- // combining the first and the second half
- int[] combined = upperArr1.Concat(upperArr2).ToArray();
- // getting the sum of the arrays
- for (int i = 0; i < 2*k; i++)
- {
- sumArr[i] = combined[i] + midArr[i];
- }
- for (int i = 0; i < 2 * k; i++)
- {
- Console.Write(sumArr[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement