Advertisement
danielaavramova

rotate and sum

Oct 11th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 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 _02.Rotate_and_Sum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string[] input = Console.ReadLine().Split();
  14. long rotation = long.Parse(Console.ReadLine());
  15.  
  16. int[] nums = ParseNums(input);
  17. long[] sum = new long[input.Length];
  18.  
  19. MakeRotation(nums, sum, rotation);
  20.  
  21. Console.WriteLine(string.Join(" ", sum));
  22. }
  23.  
  24. private static void MakeRotation(int[] nums, long[] sum, long rotation)
  25. {
  26. for (int i = 0; i < rotation; i++)
  27. {
  28. int last = nums[nums.Length - 1];
  29. for (int j = nums.Length - 1 ; j >= 0; j++)
  30. {
  31. nums[j] = nums[j - 1];
  32. }
  33. nums[0] = last;
  34.  
  35. for (int a = 0; a < nums.Length; a++)
  36. {
  37. sum[a] += nums[a];
  38. }
  39.  
  40. }
  41. }
  42.  
  43. private static int[] ParseNums(string[] input)
  44. {
  45. int[] nums = new int[input.Length];
  46. for (int i = 0; i < input.Length; i++)
  47. {
  48. nums[i] = int.Parse(input[i]);
  49. }
  50. return nums;
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement