Advertisement
YavorGrancharov

Snowmen(ExamTask02)05.01.18

Jan 6th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Snowmen
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             List<int> snowmen = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.  
  13.             HashSet<int> loosers = new HashSet<int>();
  14.  
  15.             while(snowmen.Count > 1)
  16.             {
  17.                 for (int attacker = 0; attacker < snowmen.Count; attacker++)
  18.                 {
  19.                     if (!loosers.Contains(attacker))
  20.                     {
  21.                         if (snowmen[attacker] >= snowmen.Count)
  22.                         {
  23.                             int target = snowmen[attacker] % snowmen.Count;
  24.                             int diff = Math.Abs(attacker - target);
  25.                             if (attacker == target)
  26.                             {
  27.                                 Console.WriteLine("{0} performed harakiri", attacker);
  28.                                 loosers.Add(attacker);
  29.                             }
  30.                             else if (diff % 2 == 0)
  31.                             {
  32.                                 Console.WriteLine("{0} x {1} -> {2} wins", attacker, target, attacker);
  33.                                 loosers.Add(target);
  34.                             }
  35.                             else
  36.                             {
  37.                                 Console.WriteLine("{0} x {1} -> {2} wins", attacker, target, target);
  38.                                 loosers.Add(attacker);
  39.                             }
  40.                         }
  41.                         else
  42.                         {
  43.                             int target = snowmen[attacker];
  44.                             int diff = Math.Abs(attacker - target);
  45.                             if (attacker == target)
  46.                             {
  47.                                 Console.WriteLine("{0} performed harakiri", attacker);
  48.                                 loosers.Add(attacker);
  49.                             }
  50.                             else if (diff % 2 == 0)
  51.                             {
  52.                                 Console.WriteLine("{0} x {1} -> {2} wins", attacker, target, attacker);
  53.                                 loosers.Add(target);
  54.                             }
  55.                             else
  56.                             {
  57.                                 Console.WriteLine("{0} x {1} -> {2} wins", attacker, target, target);
  58.                                 loosers.Add(attacker);
  59.                             }
  60.  
  61.                         }
  62.                         if (snowmen.Count - loosers.Count == 1)
  63.                         {
  64.                             return;
  65.                         }
  66.                     }
  67.                 }
  68.                 foreach (var index in loosers)
  69.                 {
  70.                     snowmen[index] = -1;
  71.                 }
  72.                 loosers.Clear();
  73.                 snowmen = snowmen.Where(x => x != -1).ToList();
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement