kirililchev3

Rotate and sum

Jun 3rd, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. namespace Rotate_and_Sum
  2. {
  3.     using System;
  4.  
  5.     public class RotateAndSum
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             string[] input = Console.ReadLine().Split(' ');
  10.             int[] nums = new int[input.Length];
  11.             for (int i = 0; i < nums.Length; i++)
  12.             {
  13.                 if (input.Length > 0)
  14.                 {
  15.                     nums[i] = int.Parse(input[i]);
  16.                 }
  17.             }
  18.  
  19.             int k = int.Parse(Console.ReadLine());
  20.             int[] sums = new int[nums.Length];
  21.  
  22.             for (int i = 0; i < k; i++)
  23.             {
  24.                 int temp = nums[0];
  25.                 nums[0] = nums[nums.Length - 1];
  26.                 for (int m = 1; m < nums.Length; m++)
  27.                 {
  28.                     int internalTemp = nums[m];
  29.                     nums[m] = temp;
  30.                     temp = internalTemp;
  31.                 }
  32.  
  33.                 for (int j = 0; j < sums.Length; j++)
  34.                 {
  35.                     sums[j] += nums[j];
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine(string.Join(" ", sums));
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment