Advertisement
TeMePyT

Untitled

May 26th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 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. int sequenceLength = samuraiMasters.Count;
  13. bool[] deadIndexes = new bool[sequenceLength];
  14. for (int i = 0; i < sequenceLength; i++)
  15. {
  16. deadIndexes[i] = true;
  17. }
  18. int trueCount = trueCount = deadIndexes.Count(x => x);
  19.  
  20. while (trueCount != 1)
  21. {
  22. for (int attackerIndex = 0; attackerIndex < sequenceLength; attackerIndex++)
  23. {
  24.  
  25. if (deadIndexes[attackerIndex] == false)
  26. {
  27. continue;
  28. }
  29. int targetIndex = samuraiMasters[attackerIndex] % sequenceLength;
  30.  
  31. int difference = Math.Abs(attackerIndex - targetIndex);
  32.  
  33. if (difference == 0)
  34. {
  35. deadIndexes[attackerIndex] = false; ;
  36. Console.WriteLine($"{attackerIndex} performed harakiri");
  37. //samuraiMasters.RemoveAt(attackerIndex);
  38. }
  39. else if (difference % 2 != 0)
  40. {
  41. deadIndexes[attackerIndex] = false; ;
  42. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {targetIndex} wins");
  43. // samuraiMasters.RemoveAt(attackerIndex);
  44. }
  45. else if (difference % 2 == 0)
  46. {
  47. deadIndexes[targetIndex] = false;
  48. Console.WriteLine($"{attackerIndex} x {targetIndex} -> {attackerIndex} wins");
  49. //samuraiMasters.RemoveAt(targetIndex);
  50. }
  51.  
  52. trueCount = deadIndexes.Count(x => x);
  53. }
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement