Advertisement
Guest User

Snowman

a guest
Jan 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. namespace _16_First_exam_prep
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class Startup
  7.     {
  8.         public static void Main()
  9.         {
  10.             // Problem 2 - Snowman
  11.  
  12.             int[] inputArr = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(e => int.Parse(e)).ToArray();
  13.  
  14.             while (inputArr.Length != 1)
  15.             {
  16.                 bool[] checkAttackers = new bool[inputArr.Length];
  17.                 checkAttackers = checkAttackers.Select(e => true).ToArray();
  18.  
  19.                 for (int i = 0; i < inputArr.Length; i++)
  20.                 {
  21.                     if (checkAttackers.Where(e => e).ToArray().Length == 1)
  22.                     {
  23.                         break;
  24.                     }
  25.  
  26.                     if (!checkAttackers[i])
  27.                     {
  28.                         continue;
  29.                     }
  30.  
  31.                     int attacker = i;
  32.                     int target = inputArr[i];
  33.                     int winner = new int();
  34.  
  35.                     if (target >= inputArr.Length)
  36.                     {
  37.                         target %= inputArr.Length;
  38.                     }
  39.  
  40.                     int diff = Math.Abs(attacker - target);
  41.  
  42.                     if (diff == 0)
  43.                     {
  44.                         Console.WriteLine($"{attacker} performed harakiri");
  45.  
  46.                         checkAttackers[target] = false;
  47.                         continue;
  48.                     }
  49.                     else if (diff % 2 == 0)
  50.                     {
  51.                         winner = attacker;
  52.  
  53.                         // Loser
  54.                         checkAttackers[target] = false;
  55.                     }
  56.                     else if (diff % 2 == 1)
  57.                     {
  58.                         winner = target;
  59.  
  60.                         // Loser
  61.                         checkAttackers[attacker] = false;
  62.                     }
  63.  
  64.                     Console.WriteLine($"{attacker} x {target} -> {winner} wins");
  65.                 }
  66.  
  67.                 inputArr = inputArr.Where((e, i) => checkAttackers[i]).ToArray();
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement