Boris-Stavrev92

Untitled

Jan 16th, 2018
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Problem
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. try
  14. {
  15. List<int> listOfNumbers = Console.ReadLine()
  16. .Split(' ')
  17. .Select(int.Parse)
  18. .ToList();
  19.  
  20. // 0 1 2 3 4 5 6 => 7
  21. // 25 31 6 9 2 4 7
  22.  
  23. List<int> loserList = new List<int>();
  24.  
  25. while (listOfNumbers.Count != 1)
  26. {
  27. for (int index = 0; index < listOfNumbers.Count; index++)
  28. {
  29. if (Math.Abs(loserList.Count - listOfNumbers.Count) == 1)
  30. {
  31. continue;
  32. }
  33.  
  34. if (loserList.Contains(index))
  35. {
  36. continue;
  37. }
  38.  
  39. int attackerIndex = index;
  40. int targteIndex = ValidIndex(listOfNumbers[attackerIndex], listOfNumbers.Count);
  41. int absoluteValue = Math.Abs(attackerIndex - targteIndex);
  42.  
  43. if (absoluteValue == 0)
  44. {
  45. Console.WriteLine($"{attackerIndex} performed harakiri");
  46. loserList.Add(attackerIndex);
  47. loserList = loserList.Distinct().ToList();
  48. }
  49.  
  50. if (absoluteValue != 0 && absoluteValue % 2 == 0)
  51. {
  52. Console.WriteLine($"{attackerIndex} x {targteIndex} -> {attackerIndex} wins");
  53. loserList.Add(targteIndex);
  54. loserList = loserList.Distinct().ToList();
  55. }
  56.  
  57. if (absoluteValue % 2 == 1)
  58. {
  59. Console.WriteLine($"{attackerIndex} x {targteIndex} -> {targteIndex} wins");
  60. loserList.Add(attackerIndex);
  61. loserList = loserList.Distinct().ToList();
  62. }
  63. }
  64.  
  65. foreach (var index in loserList.OrderByDescending(x => x).Distinct())
  66. {
  67. listOfNumbers.RemoveAt(index);
  68. }
  69.  
  70. loserList.Clear();
  71. }
  72. }
  73. catch
  74. {
  75.  
  76. }
  77. }
  78.  
  79. private static int ValidIndex(int index, int lenght)
  80. {
  81. if (index >= lenght)
  82. {
  83. index = index % lenght;
  84. }
  85. return index;
  86. }
  87.  
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment