Advertisement
NelIfandieva

Snowmen_Pro02_ExamJan2018

Feb 27th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Globalization;
  6.  
  7. namespace Feb26_2018
  8. {
  9.     class MainClass
  10.     {
  11.         /* */
  12.  
  13.         public static void Main()
  14.         {
  15.             //int k = int.Parse(Console.ReadLine());
  16.             //var input = Console.ReadLine()
  17.             //                   .Split()
  18.             //                   .Select(double.Parse)
  19.             //                   .ToList();
  20.  
  21.             //var firstK = input.Take(k);
  22.             //var asd = input.ToArray().Reverse();
  23.             //Console.WriteLine(asd);
  24.  
  25.  
  26.             var input = Console.ReadLine();
  27.             string[] inputToArray = input.Split();
  28.             List<int> snowmen = new List<int>();
  29.             int attacker = 0;
  30.             int target = 0;
  31. //            int remainderTargetToLength = 0;
  32.             for (int assignmentIndex = 0; assignmentIndex < inputToArray.Length; assignmentIndex++)
  33.             {
  34.                 snowmen[assignmentIndex] = int.Parse(inputToArray[assignmentIndex]);
  35.             }
  36.             for (int gameRound = 0; gameRound < snowmen.Count(); gameRound++)
  37.             {
  38.                 while(snowmen.Count() > 1)
  39.                 {
  40.                     attacker = gameRound;
  41.                     target = snowmen[gameRound];
  42.                     int winner = 0;
  43.                     bool attackerWins = Math.Abs(attacker - target) % 2 == 0;
  44.                     bool targetWins = Math.Abs(attacker - target) % 2 != 0;
  45.                     bool attackerSuicides = attacker == target;
  46.                     if (target > snowmen.Count())
  47.                     {
  48.                         target = target % snowmen.Count();
  49.                     }
  50.                     if (attackerWins)
  51.                     {
  52.                         winner = attacker;
  53.                         snowmen.RemoveAt(gameRound);
  54.                     }
  55.                     else if (targetWins)
  56.                     {
  57.                         winner = target;
  58.                         snowmen.RemoveAt(gameRound);
  59.                     }
  60.                     else if (attackerSuicides)
  61.                     {
  62.                         snowmen.RemoveAt(attacker);
  63.                     }
  64.                     if (winner == attacker || winner == target)
  65.                     {
  66.                         Console.WriteLine($"{attacker} x {target} -> {winner} wins");
  67.                     }
  68.                     else if (attackerSuicides)
  69.                     {
  70.                         Console.WriteLine($"{attacker} performed harakiri.");
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement