Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 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. Sum(arr, sumArray);
  21. }
  22.  
  23. Console.WriteLine(string.Join(" ", sumArray));
  24. }
  25.  
  26. private static void Sum(int[] arr, int[] sumArray)
  27. {
  28. for (int i = 0; i < sumArray.Length; i++)
  29. {
  30. sumArray[i] += arr[i];
  31. }
  32. }
  33.  
  34. private static void Shift(int[] arr)
  35. {
  36. int last = arr[arr.Length - 1];
  37.  
  38. for (int i = arr.Length - 1; i > 0; i--)
  39. {
  40. arr[i] = arr[i - 1];
  41. }
  42.  
  43. arr[0] = last;
  44.  
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement