Advertisement
koksibg

Rotate_and_Sum

Oct 6th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Linq;
  4.  
  5. namespace Rotate_and_Sum
  6. {
  7.     class Rotate_and_Sum
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int k = int.Parse(Console.ReadLine());
  13.             int[] sumResult = new int[array.Length];
  14.             for (int i = 0; i < k; i++)
  15.             {
  16.                 int last = array.Last();
  17.                 for (int j = array.Length - 1; j > 0; j--)
  18.                 {
  19.                     array[j] = array[j - 1];
  20.                 }
  21.                 array[0] = last;
  22.                 for (int m = 0; m < sumResult.Length; m++)
  23.                 {
  24.                     sumResult[m] += array[m];
  25.                 }
  26.             }
  27.             Console.WriteLine(string.Join(" ", sumResult));
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement