Guest User

ArrayRotation

a guest
Oct 9th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ArrayRotation
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. for (int i = 0; i < n; i++)
  14. {
  15. int[] tempArr = new int[arr.Length];
  16. for (int j = 0; j < tempArr.Length; j++)
  17. {
  18. if (j + 1 > tempArr.Length - 1)
  19. {
  20. tempArr[j] = arr[0];
  21. }
  22. else
  23. {
  24. tempArr[j] = arr[j + 1];
  25. }
  26. }
  27. arr = tempArr;
  28. }
  29. for (int i = 0; i < arr.Length; i++)
  30. {
  31. Console.Write(arr[i] + " ");
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment