Advertisement
nassss

Untitled

Mar 20th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 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.  
  16. var numberToBeShuffle = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  17. var outputList = new List<int>();
  18. for (int i = 0; i < N; i++)
  19. {
  20. outputList.Add(i + 1);
  21. }
  22.  
  23. for (int i = 0; i < numberToBeShuffle.Count; i++)
  24. {
  25. int searchedNum = 0;
  26. if (numberToBeShuffle[i] % 2 == 0)
  27. {
  28. searchedNum = numberToBeShuffle[i] / 2;
  29. }
  30. else if (numberToBeShuffle[i] % 2 == 1)
  31. {
  32. searchedNum = numberToBeShuffle[i] * 2;
  33. if (searchedNum > N)
  34. {
  35. searchedNum = N;
  36. }
  37. }
  38. position = outputList.FindIndex(x => x == searchedNum);
  39. if (searchedNum == numberToBeShuffle[i])
  40. {
  41. continue;
  42. }
  43. else
  44. {
  45. var item = outputList[i];
  46. outputList.Remove(i);
  47. outputList.Insert(position, numberToBeShuffle[i]);
  48. }
  49. }
  50. Console.WriteLine(string.Join(" ",outputList));
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement