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 numberToBeShuffle = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- var outputList = new LinkedList<int>(Enumerable.Range(1, nAndK[0]));
- if ((nAndK[0] <=1 && nAndK[0] >100) || (nAndK[1]<=1 && nAndK[1]>400000))
- {
- throw new ArgumentOutOfRangeException("Input is out of range!");
- }
- for (int j = 0; j < nAndK[1]; j++)
- {
- if (numberToBeShuffle[j] % 2 == 1 && numberToBeShuffle[j] == nAndK[0])
- {
- continue;
- }
- outputList.Remove(numberToBeShuffle[j]);
- switch (numberToBeShuffle[j] % 2)
- {
- case 0:
- outputList.AddAfter(outputList.Find(numberToBeShuffle[j] / 2), numberToBeShuffle[j]);
- break;
- case 1:
- if (numberToBeShuffle[j] * 2 > nAndK[0])
- {
- outputList.AddAfter(outputList.Find(nAndK[0]), numberToBeShuffle[j]);
- break;
- }
- outputList.AddAfter(outputList.Find(numberToBeShuffle[j] * 2), numberToBeShuffle[j]);
- break;
- default: break;
- }
- }
- Console.WriteLine(string.Join(" ", outputList));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment