Advertisement
bodyquest

Fold & Sum with LINQ

Feb 8th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Fold_And_Sum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var arr = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  14. int k = arr.Length / 4;
  15.  
  16. var arrTop = arr.Take(k).Reverse().Concat(arr.Skip(3 * k).Reverse()).ToArray();
  17. var bottom = arr.Skip(k).Take(3 * k - k).ToArray();
  18. var result = arrTop.Zip(bottom, (x, y) => x + y).ToArray();
  19.  
  20. Console.WriteLine(string.Join(" ", result));
  21.  
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement