Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- public class FoldAndSum
- {
- public static void Main()
- {
- //int[] array = Console.ReadLine().Split(' ')
- // .Select(int.Parse)
- // .ToArray();
- //int[] firstPart = new int[array.Length / 4];
- //int[] secondPart = new int[array.Length / 4];
- //int[] thirdPart = new int[array.Length / 4];
- //int[] forthPart = new int[array.Length / 4];
- //int position = 0;
- //int part = array.Length / 4;
- //for (int i = position, j = 0; position < part; position++, j++)
- //{
- // firstPart[j] = array[position];
- //}
- //for (int i = position, j = 0; position < (part * 2); position++, j++)
- //{
- // secondPart[j] = array[position];
- //}
- //for (int i = position, j = 0; position < (part * 3); position++, j++)
- //{
- // thirdPart[j] = array[position];
- //}
- //for (int i = position, j = 0; position < (part * 4); position++, j++)
- //{
- // forthPart[j] = array[position];
- //}
- //Array.Reverse(firstPart);
- //Array.Reverse(forthPart);
- //int[] firstHaft = new int[array.Length / 2];
- //int[] secondHaft = new int[firstHaft.Length];
- //for (int i = 0, j = firstPart.Length; i < firstPart.Length; i++, j++)
- //{
- // firstHaft[i] = firstPart[i];
- // firstHaft[j] = forthPart[i];
- // secondHaft[i] = secondPart[i];
- // secondHaft[j] = thirdPart[i];
- //}
- //int[] sumResul = new int[firstHaft.Length];
- //for (int i = 0; i < firstHaft.Length; i++)
- //{
- // sumResul[i] += firstHaft[i] + secondHaft[i];
- //}
- //foreach (int result in sumResul)
- //{
- // Console.Write(result + " ");
- //}
- int[] numbers = Console.ReadLine().Split(' ')
- .Select(int.Parse)
- .ToArray();
- int[] leftHaft = new int[numbers.Length / 2];
- int[] rightHaft = new int[numbers.Length / 2];
- for (int i = leftHaft.Length - 1, j = numbers.Length -1, k = 0; i >= 0; i--, j--, k++)
- {
- leftHaft[k] = numbers[i];
- rightHaft[k] = numbers[j];
- }
- int[] revLeftHaft = new int[leftHaft.Length / 2];
- int[] revRightHaft = new int[leftHaft.Length / 2];
- for (int i = 0 , k = revLeftHaft.Length; i < revLeftHaft.Length; i++, k++)
- {
- revLeftHaft[i] = leftHaft[k];
- revRightHaft[i] = rightHaft[i];
- }
- int[] sumLeft = new int[leftHaft.Length];
- int[] sumRight = new int[rightHaft.Length];
- for (int i = 0, j = rightHaft.Length, k = revLeftHaft.Length; i < revRightHaft.Length; i++, k++, j++)
- {
- sumLeft[i] = revLeftHaft[i];
- sumLeft[k] = revRightHaft[i];
- sumRight[i] = numbers[k];
- sumRight[k] = numbers[j];
- }
- int[] result = new int[numbers.Length / 2];
- for (int i = 0; i < rightHaft.Length; i++)
- {
- result[i] += sumLeft[i] + sumRight[i];
- }
- foreach (var item in result)
- {
- Console.Write(item + " ");
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement