nikolayneykov

Untitled

Feb 9th, 2019
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.35 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 Snowmen
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> input = Console.ReadLine()
  14.                 .Split(' ')
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.             while (input.Count > 1)
  18.             {
  19.                 List<int> deadIndexes = new List<int>();
  20.  
  21.                 for (int attackerIndex = 0; attackerIndex < input.Count; attackerIndex++)
  22.                 {
  23.                     if (!deadIndexes.Contains(attackerIndex) && deadIndexes.Count < input.Count - 1)
  24.                     {
  25.                         int targetIndex = input[attackerIndex] % input.Count;
  26.                         int diff = Math.Abs(attackerIndex - targetIndex);
  27.                         if (targetIndex == attackerIndex)
  28.                         {
  29.                             if (!deadIndexes.Contains(attackerIndex))
  30.                             {
  31.                                 deadIndexes.Add(attackerIndex);
  32.                             }
  33.                             Console.WriteLine($"{attackerIndex} performed harakiri");
  34.                         }
  35.                         else if (diff % 2 == 0)
  36.                         {
  37.                             if (!deadIndexes.Contains(targetIndex))
  38.                             {
  39.                                 deadIndexes.Add(targetIndex);
  40.                             }
  41.                             Console.WriteLine($"{attackerIndex} x {targetIndex} -> {attackerIndex} wins");
  42.                         }
  43.                         else
  44.                         {
  45.                             if (!deadIndexes.Contains(attackerIndex))
  46.                             {
  47.                                 deadIndexes.Add(attackerIndex);
  48.                             }
  49.                             Console.WriteLine($"{attackerIndex} x {targetIndex} -> {targetIndex} wins");
  50.                         }
  51.                     }
  52.                 }
  53.                
  54.                 for (int i = 0; i < deadIndexes.Count; i++)
  55.                 {
  56.                     int indexToRemove = deadIndexes[i];
  57.                     input[indexToRemove] = -1;
  58.                 }
  59.                 input.RemoveAll(x => x == -1);
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment