Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 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.  
  16.                 long[] firstRotate = (long[])numbers.Clone();
  17.                 long[] sum = new long[firstRotate.Length];
  18.  
  19.                 for (long i = 0; i < rotates; i++)
  20.                 {
  21.                     firstRotate = RotateArray(firstRotate);
  22.                     sum = GetSum(sum, firstRotate);
  23.                 }
  24.  
  25.                 for (long i = 0; i < sum.Length; i++)
  26.                 {
  27.                     Console.Write(sum[i] + " ");
  28.                 }
  29.            // }
  30.         }
  31.  
  32.         private static long[] RotateArray(long[] firstRotate)
  33.         {
  34.             if (firstRotate.Length <= 1)
  35.             {
  36.                 return firstRotate;
  37.             }
  38.  
  39.             long[] rotateArray = new long[firstRotate.Length];
  40.             //Last symbol is goint to index 0
  41.             rotateArray[0] = firstRotate[firstRotate.Length - 1];
  42.  
  43.             rotateArray[rotateArray.Length - 1] = firstRotate[firstRotate.Length - 2];
  44.             for (long i = 1; i <= firstRotate.Length - 2; i++)
  45.             {
  46.                 rotateArray[i] = firstRotate[i - 1];
  47.  
  48.             }
  49.             return rotateArray;
  50.         }
  51.  
  52.         static long[] GetSum(long[] sum, long[] firstRotate)
  53.         {
  54.  
  55.             for (long i = 0; i < sum.Length; i++)
  56.             {
  57.                 sum[i] += firstRotate[i];
  58.             }
  59.             return sum;
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement