Advertisement
elena1234

FoldAndSum

Sep 17th, 2020 (edited)
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace FoldAndSum
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             List<int> leftEnd = new List<int>();
  13.             List<int> rigthEnd = new List<int>();
  14.             List<int> middle = new List<int>();
  15.             List<int> sumResult = new List<int>();
  16.             int middleLength = numbers.Count / 2;
  17.             int endLength = numbers.Count / 4;
  18.             for (int i = numbers.Count-(middleLength+endLength+1); i >= 0; i--)
  19.             {
  20.                 leftEnd.Add(numbers[i]);
  21.             }
  22.  
  23.             for (int i = numbers.Count-1; i >=middleLength+ endLength; i--)
  24.             {
  25.                 rigthEnd.Add(numbers[i]);
  26.             }
  27.  
  28.             for (int i = endLength; i < endLength+middleLength; i++)
  29.             {
  30.                 middle.Add(numbers[i]);
  31.             }
  32.  
  33.             var listLeftAndRightEnds = leftEnd.Concat(rigthEnd).ToList();
  34.             for (int i = 0; i < middle.Count; i++)
  35.             {
  36.                 sumResult.Add(listLeftAndRightEnds[i] + middle[i]);
  37.             }
  38.    
  39.             Console.WriteLine(string.Join(" ",sumResult));
  40.         }
  41.       }
  42.     }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement