Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02._Rotate_and_Sum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arrToRotate = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int rotationsNum = int.Parse(Console.ReadLine());
- int[] sumArr = GetSumOfRotatedArrays(arrToRotate, rotationsNum);
- PrintSumOfArrays(sumArr);
- }
- static int[] ArrayRightToLeftRotation(int[] arr)
- {
- int[] rotatedArr = new int[arr.Length];
- for (int rotate = 0; rotate < 1; rotate++)
- {
- rotatedArr[rotate] = arr[arr.Length - 1 - rotate];
- for (int i = 0; i < arr.Length - 1; i++)
- {
- rotatedArr[i + 1] = arr[i];
- }
- }
- return rotatedArr;
- }
- static int[] GetSumOfRotatedArrays(int[] arrToRotate, int rotationsNum)
- {
- int[] sumArr = new int[arrToRotate.Length];
- int[] rotatedArr = new int[arrToRotate.Length];
- rotatedArr = ArrayRightToLeftRotation(arrToRotate);
- for (int i = 0; i < rotationsNum; i++)
- {
- for (int k = 0; k < sumArr.Length; k++)
- {
- sumArr[k] = sumArr[k] + rotatedArr[k];
- }
- rotatedArr = ArrayRightToLeftRotation(rotatedArr);
- }
- return sumArr;
- }
- static void PrintSumOfArrays(int[] sumArr)
- {
- foreach (var num in sumArr)
- {
- Console.Write($"{num} ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement