simonradev

RotateAndSum

Jan 26th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace RotateAndSum
  5. {
  6.     class Program
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.             int rotations = int.Parse(Console.ReadLine());
  12.            
  13.             int[] sum = new int[array.Length];
  14.             int[] arrayAfterRotation = new int[array.Length];
  15.            
  16.             for (int rotation = 1; rotation <= rotations; rotation++)
  17.             {
  18.                 for (int currentElement = 0; currentElement < array.Length; currentElement++)
  19.                 {
  20.                     arrayAfterRotation[currentElement] = array[(array.Length - 1 + currentElement) % array.Length];
  21.                     sum[currentElement] += arrayAfterRotation[currentElement];
  22.                 }  
  23.                
  24.                 array = arrayAfterRotation.ToArray();
  25.             }
  26.            
  27.             Console.WriteLine(string.Join(" ", sum));
  28.            
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment