Advertisement
bullit3189

Gauss Trick - Lists

Jan 23rd, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. List<long>numbers = Console.ReadLine().Split().Select(long.Parse).ToList();
  10.  
  11. List<long>result = new List<long>();
  12.  
  13. for (int i=0; i<numbers.Count/2; i++)
  14. {
  15. long firstNum = numbers[i];
  16. long lastNum = numbers[numbers.Count-1-i];
  17.  
  18. result.Add(firstNum+lastNum);
  19. }
  20.  
  21. if (numbers.Count%2==1)
  22. {
  23. result.Add(numbers[numbers.Count/2]);
  24. }
  25.  
  26. Console.WriteLine(string.Join(" ",result));
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement