nassss

Untitled

Mar 21st, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Shuffle
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var nAndK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12. var N = nAndK[0];
  13. var K = nAndK[1];
  14. int position;
  15. var numberToBeShuffle = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  16. var queue = new Queue<int>(numberToBeShuffle);
  17.  
  18. var outputList = new List<int>();
  19. for (int i = 0; i < N; i++)
  20. {
  21. outputList.Add(i + 1);
  22. }
  23.  
  24. for (int i = 0; i < K; i++)
  25. {
  26. int searchedNum = 0;
  27. int current = queue.Dequeue();
  28.  
  29. if (current % 2 == 0)
  30. {
  31. outputList.Remove(current);
  32. position = outputList.FindIndex(x => x == current / 2);
  33. outputList.Insert(position + 1, current);
  34. continue;
  35. }
  36. else if (current % 2 == 1)
  37. {
  38. searchedNum = current * 2;
  39. if (searchedNum >= N)
  40. {
  41. continue;
  42. }
  43. }
  44. outputList.Remove(current);
  45. position = outputList.FindIndex(x => x == current * 2);
  46. outputList.Insert(position + 1, current);
  47. }
  48. Console.WriteLine(string.Join(" ", outputList));
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment