Advertisement
Sim0o0na

Untitled

Feb 25th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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.Snowmen
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var snowmen = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  14.  
  15. while (snowmen.Count > 1)
  16. {
  17. var lostOrHarakiriIndices = new List<int>();
  18.  
  19. for (int i = 0; i < snowmen.Count; i++)
  20. {
  21. var attacker = i;
  22. var target = snowmen[attacker];
  23.  
  24. if (lostOrHarakiriIndices.Contains(attacker) || lostOrHarakiriIndices.Distinct().ToList().Count == snowmen.Count - 1)
  25. {
  26. continue;
  27. }
  28.  
  29. if (target > snowmen.Count - 1)
  30. {
  31. target %= snowmen.Count;
  32. }
  33.  
  34. if (attacker == target)
  35. {
  36. Console.WriteLine($"{attacker} performed harakiri");
  37. lostOrHarakiriIndices.Add(attacker);
  38. }
  39. else if (Math.Abs(attacker - target) % 2 == 0)
  40. {
  41. Console.WriteLine($"{attacker} x {target} -> {attacker} wins");
  42. lostOrHarakiriIndices.Add(target);
  43. }
  44. else if (Math.Abs(attacker - target) % 2 != 0)
  45. {
  46. Console.WriteLine($"{attacker} x {target} -> {target} wins");
  47. lostOrHarakiriIndices.Add(attacker);
  48. }
  49.  
  50. }
  51.  
  52. for (int j = 0; j < lostOrHarakiriIndices.Count; j++)
  53. {
  54. lostOrHarakiriIndices = lostOrHarakiriIndices.OrderByDescending(x => x).Distinct().ToList();
  55. snowmen.RemoveAt(lostOrHarakiriIndices[j]);
  56. }
  57. }
  58.  
  59. //Console.WriteLine(snowmen.Count);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement