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 FoldAndSum
- {
- class FoldAndSum
- {
- static void Main(string[] args)
- {
- int[] inputArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int sizeOfAQuarter = inputArray.Length / 4;
- int newArraysLengh = inputArray.Length / 2;
- int[] foldedEndsOfTheInputArr = new int[newArraysLengh];
- for (int firstHalfElement = 0, secondHalfElement = (foldedEndsOfTheInputArr.Length / 2); firstHalfElement < sizeOfAQuarter; firstHalfElement++, secondHalfElement++)
- {
- foldedEndsOfTheInputArr[firstHalfElement] = inputArray[sizeOfAQuarter - 1 - firstHalfElement];
- foldedEndsOfTheInputArr[secondHalfElement] = inputArray[inputArray.Length - 1 - firstHalfElement];
- }
- int[] resultArray = new int[newArraysLengh];
- for (int currElement = 0; currElement < foldedEndsOfTheInputArr.Length; currElement++)
- {
- resultArray[currElement] = foldedEndsOfTheInputArr[currElement] + inputArray[sizeOfAQuarter + currElement];
- }
- Console.WriteLine(string.Join(" ", resultArray));
- }
- }
- }
Add Comment
Please, Sign In to add comment