nassss

Untitled

Mar 21st, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 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 numberToBeShuffle = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  13.  
  14. var outputList = new LinkedList<int>(Enumerable.Range(1, nAndK[0]));
  15.  
  16. if ((nAndK[0] <=1 && nAndK[0] >100) || (nAndK[1]<=1 && nAndK[1]>400000))
  17. {
  18. throw new ArgumentOutOfRangeException("Input is out of range!");
  19. }
  20. for (int j = 0; j < nAndK[1]; j++)
  21. {
  22. if (numberToBeShuffle[j] % 2 == 1 && numberToBeShuffle[j] == nAndK[0])
  23. {
  24. continue;
  25. }
  26. outputList.Remove(numberToBeShuffle[j]);
  27. switch (numberToBeShuffle[j] % 2)
  28. {
  29. case 0:
  30. outputList.AddAfter(outputList.Find(numberToBeShuffle[j] / 2), numberToBeShuffle[j]);
  31. break;
  32. case 1:
  33. if (numberToBeShuffle[j] * 2 > nAndK[0])
  34. {
  35. outputList.AddAfter(outputList.Find(nAndK[0]), numberToBeShuffle[j]);
  36. break;
  37. }
  38. outputList.AddAfter(outputList.Find(numberToBeShuffle[j] * 2), numberToBeShuffle[j]);
  39. break;
  40. default: break;
  41. }
  42. }
  43. Console.WriteLine(string.Join(" ", outputList));
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment