Advertisement
Guest User

Untitled

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