Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _02.Snowmen
- {
- class Program
- {
- static void Main(string[] args)
- {
- var snowmen = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- while (snowmen.Count > 1)
- {
- var lostOrHarakiriIndices = new List<int>();
- for (int i = 0; i < snowmen.Count; i++)
- {
- var attacker = i;
- var target = snowmen[attacker];
- if (lostOrHarakiriIndices.Contains(attacker) || lostOrHarakiriIndices.Distinct().ToList().Count == snowmen.Count - 1)
- {
- continue;
- }
- if (target > snowmen.Count - 1)
- {
- target %= snowmen.Count;
- }
- if (attacker == target)
- {
- Console.WriteLine($"{attacker} performed harakiri");
- lostOrHarakiriIndices.Add(attacker);
- }
- else if (Math.Abs(attacker - target) % 2 == 0)
- {
- Console.WriteLine($"{attacker} x {target} -> {attacker} wins");
- lostOrHarakiriIndices.Add(target);
- }
- else if (Math.Abs(attacker - target) % 2 != 0)
- {
- Console.WriteLine($"{attacker} x {target} -> {target} wins");
- lostOrHarakiriIndices.Add(attacker);
- }
- }
- for (int j = 0; j < lostOrHarakiriIndices.Count; j++)
- {
- lostOrHarakiriIndices = lostOrHarakiriIndices.OrderByDescending(x => x).Distinct().ToList();
- snowmen.RemoveAt(lostOrHarakiriIndices[j]);
- }
- }
- //Console.WriteLine(snowmen.Count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement