anizko

2. Gauss' Trick

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