kalitarix

Snowmen

Jan 22nd, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Snowmen_01_18
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> snowmen = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             List<int> losers = new List<int>();
  13.  
  14.             while (snowmen.Count > 1)
  15.             {
  16.                 for (int index = 0; index < snowmen.Count; index++)
  17.                 {
  18.                     if (snowmen.Count - losers.Count == 1)
  19.                     {
  20.                         break;
  21.                     }
  22.  
  23.                     int attacker = index;
  24.                     int target = snowmen[index] % snowmen.Count;
  25.  
  26.                     if (losers.Contains(attacker))
  27.                     {
  28.                         continue;
  29.                     }
  30.  
  31.                     int difference = Math.Abs(attacker - target);
  32.  
  33.                     if (difference == 0)
  34.                     {
  35.                         Console.WriteLine($"{attacker} performed harakiri");
  36.                         losers.Add(attacker);
  37.                         losers = losers.Distinct().ToList();
  38.                     }
  39.                     else if (difference % 2 == 0)
  40.                     {
  41.                         Console.WriteLine($"{attacker} x {target} -> {attacker} wins");
  42.                         losers.Add(target);
  43.                         losers = losers.Distinct().ToList();
  44.                     }
  45.                     else if (difference % 2 != 0)
  46.                     {
  47.                         Console.WriteLine($"{attacker} x {target} -> {target} wins");
  48.                         losers.Add(attacker);
  49.                         losers = losers.Distinct().ToList();
  50.                     }
  51.                 }
  52.  
  53.                 losers.Sort();
  54.                 losers.Reverse();
  55.  
  56.                 foreach (int index in losers)
  57.                 {
  58.                     snowmen.RemoveAt(index);
  59.                 }
  60.  
  61.                 losers.Clear();
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment