Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace The_Great_Samurai_Battle
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> samuraiMasters = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- bool[] deadIndexes = new bool[samuraiMasters.Count];
- for (int i = 0; i < samuraiMasters.Count; i++)
- {
- deadIndexes[i] = true;
- }
- int trueCount = deadIndexes.Count(x => x);
- int sequenceLength = samuraiMasters.Count;
- while (trueCount != 1)
- {
- for (int attackerIndex = 0; attackerIndex < sequenceLength; attackerIndex++)
- {
- int targetIndex = 0;
- if (deadIndexes.Count(x => x) == 1)
- {
- return;
- }
- if (deadIndexes[attackerIndex] == false)
- {
- continue;
- }
- if(samuraiMasters[attackerIndex]>trueCount)
- {
- targetIndex = samuraiMasters[attackerIndex] % trueCount;
- }
- else
- {
- targetIndex = samuraiMasters[attackerIndex];
- }
- int difference = Math.Abs(attackerIndex - targetIndex);
- if (difference == 0)
- {
- deadIndexes[attackerIndex] = false; ;
- Console.WriteLine($"{attackerIndex} performed harakiri");
- }
- else if (difference % 2 != 0)
- {
- deadIndexes[attackerIndex] = false; ;
- Console.WriteLine($"{attackerIndex} x {targetIndex} -> {targetIndex} wins");
- }
- else if (difference % 2 == 0)
- {
- deadIndexes[targetIndex] = false;
- Console.WriteLine($"{attackerIndex} x {targetIndex} -> {attackerIndex} wins");
- }
- }
- trueCount = deadIndexes.Count(x => x);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement