Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Shuffle
- {
- class Program
- {
- static void Main(string[] args)
- {
- var nAndK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var N = nAndK[0];
- var K = nAndK[1];
- int position;
- var numberToBeShuffle = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var queue = new Queue<int>(numberToBeShuffle);
- var outputList = new List<int>();
- for (int i = 0; i < N; i++)
- {
- outputList.Add(i + 1);
- }
- for (int i = 0; i < K; i++)
- {
- int searchedNum = 0;
- int current = queue.Dequeue();
- if (current % 2 == 0)
- {
- outputList.Remove(current);
- position = outputList.FindIndex(x => x == current / 2);
- outputList.Insert(position + 1, current);
- continue;
- }
- else if (current % 2 == 1)
- {
- searchedNum = current * 2;
- if (searchedNum >= N)
- {
- continue;
- }
- }
- outputList.Remove(current);
- position = outputList.FindIndex(x => x == current * 2);
- outputList.Insert(position + 1, current);
- }
- Console.WriteLine(string.Join(" ", outputList));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment