Advertisement
deleriumbg

Untitled

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