tanya_zheleva

02

Jan 31st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Startup
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] numbers = Console.ReadLine()
  12.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(x => int.Parse(x))
  14.                 .ToArray();
  15.             int k = int.Parse(Console.ReadLine());
  16.             int[] summed = new int[numbers.Length];
  17.  
  18.             for (int i = 0; i < k; i++)
  19.             {
  20.                 IEnumerable<int> firstPart = numbers.Reverse().Take(1);
  21.                 IEnumerable<int> lastPart = numbers.Reverse().Skip(1).Reverse();
  22.                 int[] newArray = firstPart.Concat(lastPart).ToArray();
  23.  
  24.                 Sum(summed, newArray);
  25.                 numbers = newArray;
  26.             }
  27.  
  28.             Console.WriteLine(string.Join(" ", summed));
  29.         }
  30.  
  31.         private static void Sum(int[] summed, int[] newArray)
  32.         {
  33.             for (int i = 0; i < summed.Length; i++)
  34.             {
  35.                 summed[i] += newArray[i];
  36.             }
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment