Advertisement
bacco

Rotate and Sum

May 6th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace test
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.             int[] arr = Console.ReadLine()
  12.                                    .Split(' ')
  13.                                        .Select(int.Parse)
  14.                                            .ToArray();
  15.             int[] arrSum = new int[arr.Length];
  16.  
  17.             int rotations = int.Parse(Console.ReadLine());
  18.  
  19.             for (int r = 0; r < rotations; r++)
  20.             {
  21.                 var lastSimb = arr[arr.Length - 1];
  22.  
  23.                 for (int i = 1; i < arr.Length; i++)
  24.                 {
  25.                     arr[arr.Length  - i] = arr[arr.Length - 1 - i];
  26.                 }
  27.                 arr[0] = lastSimb;
  28.  
  29.  
  30.                 for (int i = 0; i < arr.Length; i++)
  31.                 {
  32.                     arrSum[i] += arr[i];
  33.                 }
  34.             }
  35.             Console.WriteLine(string.Join(" " , arrSum));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement