Advertisement
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).ToList();
- var outputList = new List<int>();
- for (int i = 0; i < N; i++)
- {
- outputList.Add(i + 1);
- }
- for (int i = 0; i < numberToBeShuffle.Count; i++)
- {
- int searchedNum = 0;
- if (numberToBeShuffle[i] % 2 == 0)
- {
- searchedNum = numberToBeShuffle[i] / 2;
- }
- else if (numberToBeShuffle[i] % 2 == 1)
- {
- searchedNum = numberToBeShuffle[i] * 2;
- if (searchedNum > N)
- {
- searchedNum = N;
- }
- }
- position = outputList.FindIndex(x => x == searchedNum);
- if (searchedNum == numberToBeShuffle[i])
- {
- continue;
- }
- else
- {
- var item = outputList[i];
- outputList.Remove(i);
- outputList.Insert(position, numberToBeShuffle[i]);
- }
- }
- Console.WriteLine(string.Join(" ",outputList));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement