Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _16_First_exam_prep
- {
- using System;
- using System.Linq;
- public class Startup
- {
- public static void Main()
- {
- // Problem 2 - Snowman
- int[] inputArr = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(e => int.Parse(e)).ToArray();
- while (inputArr.Length != 1)
- {
- bool[] checkAttackers = new bool[inputArr.Length];
- checkAttackers = checkAttackers.Select(e => true).ToArray();
- for (int i = 0; i < inputArr.Length; i++)
- {
- if (checkAttackers.Where(e => e).ToArray().Length == 1)
- {
- break;
- }
- if (!checkAttackers[i])
- {
- continue;
- }
- int attacker = i;
- int target = inputArr[i];
- int winner = new int();
- if (target >= inputArr.Length)
- {
- target %= inputArr.Length;
- }
- int diff = Math.Abs(attacker - target);
- if (diff == 0)
- {
- Console.WriteLine($"{attacker} performed harakiri");
- checkAttackers[target] = false;
- continue;
- }
- else if (diff % 2 == 0)
- {
- winner = attacker;
- // Loser
- checkAttackers[target] = false;
- }
- else if (diff % 2 == 1)
- {
- winner = target;
- // Loser
- checkAttackers[attacker] = false;
- }
- Console.WriteLine($"{attacker} x {target} -> {winner} wins");
- }
- inputArr = inputArr.Where((e, i) => checkAttackers[i]).ToArray();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement