TeMePyT

Untitled

May 26th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 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. int targetIndex = 0;
  26. if (deadIndexes.Count(x => x) == 1)
  27. {
  28. return;
  29. }
  30. if (deadIndexes[attackerIndex] == false)
  31. {
  32. continue;
  33. }
  34. if(samuraiMasters[attackerIndex]>trueCount)
  35. {
  36. targetIndex = samuraiMasters[attackerIndex] % trueCount;
  37. }
  38. else
  39. {
  40. targetIndex = samuraiMasters[attackerIndex];
  41. }
  42. int difference = Math.Abs(attackerIndex - targetIndex);
  43. if (difference == 0)
  44. {
  45. deadIndexes[attackerIndex] = false; ;
  46. Console.WriteLine($"{attackerIndex} performed harakiri");
  47. }
  48. else if (difference % 2 != 0)
  49. {
  50. deadIndexes[attackerIndex] = false; ;
  51. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {targetIndex} wins");
  52. }
  53. else if (difference % 2 == 0)
  54. {
  55. deadIndexes[targetIndex] = false;
  56. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {attackerIndex} wins");
  57. }
  58. }
  59. trueCount = deadIndexes.Count(x => x);
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment