Advertisement
TeMePyT

Untitled

May 26th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace The_Great_Samurai_Battle
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> samuraiMasters = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.  
  13. bool[] deadIndexes = new bool[samuraiMasters.Count];
  14. for (int i = 0; i < samuraiMasters.Count; i++)
  15. {
  16. deadIndexes[i] = true;
  17. }
  18. int trueCount = deadIndexes.Count(x => x);
  19. int sequenceLength = samuraiMasters.Count;
  20.  
  21. while (trueCount != 1)
  22. {
  23. for (int attackerIndex = 0; attackerIndex < sequenceLength; attackerIndex++)
  24. {
  25.  
  26. if (trueCount == 1)
  27. {
  28. return;
  29. }
  30. if (deadIndexes[attackerIndex] == false)
  31. {
  32. continue;
  33. }
  34. int targetIndex = samuraiMasters[attackerIndex] % trueCount;
  35. int difference = Math.Abs(attackerIndex - targetIndex);
  36. if (difference == 0)
  37. {
  38. deadIndexes[attackerIndex] = false; ;
  39. Console.WriteLine($"{attackerIndex} performed harakiri");
  40. }
  41. else if (difference % 2 != 0)
  42. {
  43. deadIndexes[attackerIndex] = false; ;
  44. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {targetIndex} wins");
  45. }
  46. else if (difference % 2 == 0)
  47. {
  48. deadIndexes[targetIndex] = false;
  49. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {attackerIndex} wins");
  50. }
  51. }
  52. trueCount = deadIndexes.Count(x => x);
  53. }
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement