Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2018
111
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.Linq;
  3.  
  4. namespace _02_Rotate_and_Sum
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             long[] numbers = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  11.             long rotates = long.Parse(Console.ReadLine());
  12.  
  13.             //if (rotates >= 1)
  14.             {
  15.                 long[] firstRotate = (long[])numbers.Clone();
  16.                 long[] sum = new long[firstRotate.Length];
  17.  
  18.                 for (long i = 0; i < rotates; i++)
  19.                 {
  20.                     firstRotate = RotateArray(firstRotate);
  21.                     sum = sum.Zip(firstRotate, (x, y) => x + y).ToArray();
  22.                 }
  23.  
  24.                 for (long i = 0; i < sum.Length; i++)
  25.                 {
  26.                     Console.Write(sum[i] + " ");
  27.                 }
  28.             }
  29.         }
  30.  
  31.         private static long[] RotateArray(long[] firstRotate)
  32.         {
  33.             long[] rotateArray = new long[firstRotate.Length];
  34.             for (int i = 0; i < firstRotate.Length; i++)
  35.             {
  36.                 rotateArray[(i + 1) % rotateArray.Length] = firstRotate[i];
  37.             }
  38.             return rotateArray;
  39.         }
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement