VelizarAvramov

02. Rotate and Sum

Nov 25th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Rotate_and_Sum
  5. {
  6.     class RotateAndSum
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.             int rotations = int.Parse(Console.ReadLine());
  12.  
  13.             int[] sumArray = new int[input.Length];
  14.  
  15.             for (int i = 0; i < rotations; i++)
  16.             {
  17.                 SwitchArr(input);
  18.                 SumArray(sumArray, input);
  19.             }
  20.             Console.WriteLine(string.Join(" ", sumArray));
  21.         }
  22.  
  23.         private static void SumArray(int[] sumArray, int[] input)
  24.         {
  25.             for (int i = 0; i < sumArray.Length; i++)
  26.             {
  27.                 sumArray[i] += input[i];
  28.             }
  29.         }
  30.  
  31.         private static void SwitchArr(int[] input)
  32.         {
  33.             int last = input[input.Length - 1];
  34.  
  35.             for (int i = input.Length - 1; i > 0; i--)
  36.             {
  37.                 input[i] = input[i - 1];
  38.             }
  39.             input[0] = last;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment