Teo_Yanchev

Lists - Guass'Trick - C# Fundamentals

Sep 13th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2.Gauss_Trick
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> listNumbers = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<int> newListNumbers = new List<int>();
  17. int number = 0;
  18.  
  19. for (int i = 0; i < listNumbers.Count / 2; i++)
  20. {
  21. number = listNumbers[i] + listNumbers[listNumbers.Count -i - 1];
  22. newListNumbers.Add(number);
  23. }
  24.  
  25. if (listNumbers.Count % 2 == 1)
  26. {
  27. newListNumbers.Add(listNumbers[listNumbers.Count / 2]);
  28. }
  29.  
  30. Console.WriteLine(string.Join(" ", newListNumbers));
  31. }
  32. }
  33. }
  34.  
Add Comment
Please, Sign In to add comment