Advertisement
YavorJS

2. Rotate and Sum

Aug 17th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Arrays
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14. int rotations = int.Parse(Console.ReadLine());
  15. int[] rotated = new int[nums.Length];
  16. int[] arrSum = new int[nums.Length];
  17.  
  18. while (rotations > 0)
  19. {
  20. rotated = new int[nums.Length];
  21. rotated[0] = nums[nums.Length - 1];
  22. arrSum[0] += rotated[0];
  23. for (int i = 1; i < nums.Length; i++)
  24. {
  25. rotated[i] = nums[i - 1];
  26. arrSum[i] += rotated[i];
  27. }
  28. rotations--;
  29. nums = rotated;
  30. }
  31.  
  32. Console.WriteLine(string.Join(" ", arrSum));
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement