vstoyanov

Untitled

Jan 13th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7.  
  8. namespace ConsoleApp1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             List<int> inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  15.            
  16.  
  17.             List<int> losesIndexes = new List<int>();
  18.             int attackIndex = 0;
  19.             int attackValue = 0;
  20.             BigInteger difference = 0;
  21.  
  22.             while (inputNum.Count != 1)
  23.             {
  24.                 for (int i = 0; i < inputNum.Count; i++)
  25.                 {
  26.                     if (inputNum[i] > inputNum.Count)
  27.                     {
  28.                         inputNum[i] = inputNum[i] % inputNum.Count;
  29.                     }
  30.  
  31.                     if (losesIndexes.Contains(i))
  32.                     {
  33.                         continue;
  34.                     }
  35.  
  36.                     attackIndex = i;
  37.                     attackValue = inputNum[i];
  38.  
  39.                     difference = BigInteger.Abs(attackIndex - attackValue);
  40.  
  41.                     if (difference.IsEven && !difference.IsZero)
  42.                     {
  43.                         if (i < inputNum.Count - 1)
  44.                         {
  45.                             Console.WriteLine($"{attackIndex} x {attackValue} -> {attackIndex} wins");
  46.  
  47.                             losesIndexes.Add(attackValue);
  48.                         }
  49.                     }
  50.                     else if (!difference.IsEven)
  51.                     {
  52.                         if (i < inputNum.Count - 1)
  53.                         {
  54.                             Console.WriteLine($"{attackIndex} x {attackValue} -> {attackValue} wins");
  55.  
  56.                             losesIndexes.Add(attackIndex);
  57.                         }
  58.  
  59.                     }else if (difference.IsZero)
  60.                     {
  61.                         if (i < inputNum.Count - 1)
  62.                         {
  63.                             Console.WriteLine($"{attackIndex} performed harakiri");
  64.                             losesIndexes.Add(attackIndex);
  65.                         }
  66.                     }
  67.  
  68.                 }
  69.  
  70.                 while (losesIndexes.Count > 0)
  71.                 {
  72.                     for (int j = 0; j < losesIndexes.Count; j++)
  73.                     {
  74.  
  75.                         inputNum[losesIndexes[j]] = -10;
  76.                     }
  77.  
  78.                     //  losesIndexes.RemoveAll(a=> a>int.MinValue);
  79.  
  80.  
  81.                     for (int i = 0; i < inputNum.Count; i++)
  82.                     {
  83.                         if (inputNum[i] == -10)
  84.                         {
  85.                             inputNum.RemoveAt(i);
  86.                             i--;
  87.                         }
  88.  
  89.                        
  90.                     }
  91.                     break;
  92.                 }
  93.  
  94.  
  95.             }
  96.  
  97.                
  98.  
  99.  
  100.             }
  101.         }
  102.     }
Advertisement
Add Comment
Please, Sign In to add comment