TheBulgarianWolf

Gauss' Trick

Nov 10th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace SoftUniLists
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> list = ReadList();
  12.             for(int i = 0; i < list.Count/2; i++)
  13.             {
  14.                 Console.WriteLine(list[i] + list[list.Count-1-i]);
  15.                
  16.             }
  17.             if (list.Count % 2 != 0)
  18.             {
  19.                 Console.WriteLine(list[list.Count/2-1]);
  20.             }
  21.         }
  22.  
  23.         static List<int> ReadList(int n)
  24.         {
  25.             var list = new List<int>();
  26.             for (int i = 0; i < n; i++)
  27.             {
  28.                 list.Add(int.Parse(Console.ReadLine()));
  29.             }
  30.  
  31.             return list;
  32.         }
  33.  
  34.         static List<int> ReadList()
  35.         {
  36.             List<int> list = new List<int>();
  37.             var line = Console.ReadLine();
  38.             list = line.Split().Select(int.Parse).ToList();
  39.             return list;
  40.         }
  41.  
  42.         static void PrintList(List<int> list)
  43.         {
  44.             for (int i = 0; i < list.Count; i++)
  45.             {
  46.                 Console.WriteLine(list[i]);
  47.             }
  48.         }
  49.     }
  50. }
  51.  
Add Comment
Please, Sign In to add comment