MiroslavKisov

RotateAndSum

Oct 8th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02.RotateAndSum
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main()
  9.         {
  10.             long[] numbers = Console.ReadLine()
  11.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(long.Parse)
  13.                 .ToArray();
  14.             long k = long.Parse(Console.ReadLine());
  15.             long[] rotatedArr = new long[numbers.Length];
  16.             long[] sum = new long[numbers.Length];
  17.             for (int i = 0; i < k; i++)
  18.             {
  19.                 rotatedArr[0] = numbers[numbers.Length - 1];
  20.                 for (int j = 0, index = 1; j < numbers.Length - 1; j++, index++)
  21.                 {
  22.                     rotatedArr[index] = numbers[j];
  23.                 }
  24.                 for (int j = 0; j < numbers.Length; j++)
  25.                 {
  26.                     sum[j] += rotatedArr[j];
  27.                 }
  28.                 rotatedArr.CopyTo(numbers, 0);
  29.             }
  30.             Console.WriteLine(string.Join(" ",sum));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment