Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace FoldAndSum
- {
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- List<int> leftEnd = new List<int>();
- List<int> rigthEnd = new List<int>();
- List<int> middle = new List<int>();
- List<int> sumResult = new List<int>();
- int middleLength = numbers.Count / 2;
- int endLength = numbers.Count / 4;
- for (int i = numbers.Count-(middleLength+endLength+1); i >= 0; i--)
- {
- leftEnd.Add(numbers[i]);
- }
- for (int i = numbers.Count-1; i >=middleLength+ endLength; i--)
- {
- rigthEnd.Add(numbers[i]);
- }
- for (int i = endLength; i < endLength+middleLength; i++)
- {
- middle.Add(numbers[i]);
- }
- var listLeftAndRightEnds = leftEnd.Concat(rigthEnd).ToList();
- for (int i = 0; i < middle.Count; i++)
- {
- sumResult.Add(listLeftAndRightEnds[i] + middle[i]);
- }
- Console.WriteLine(string.Join(" ",sumResult));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement