Advertisement
mariastoilova

Snowmen

Feb 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 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.  
  7. namespace Snowmen
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> snowmen = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             int lenght = snowmen.Count-1;
  15.             int diff = 0;
  16.             int count = 0;
  17.             var winers = new List<int>();
  18.  
  19.             while (count == 0)
  20.             {
  21.  
  22.                 for (int i = 0; i < snowmen.Count - 1; i++)
  23.                 {
  24.                    
  25.                     if (snowmen[i] > snowmen.Count-1)
  26.                     {
  27.                         snowmen[i] = snowmen[i] % snowmen.Count;
  28.                     }
  29.  
  30.                     diff = Math.Abs(i - snowmen[i]);
  31.  
  32.                    
  33.                     if(snowmen[i] != i)
  34.                     {
  35.                         if (diff % 2 == 0)
  36.                         {
  37.                             Console.WriteLine($"{i} x {snowmen[i]} -> {i} wins");
  38.                             winers.Add(snowmen[i]);
  39.                         }
  40.                         else if (diff % 2 != 0)
  41.                         {
  42.                             Console.WriteLine($"{i} x {snowmen[i]} -> {snowmen[i]} wins");
  43.  
  44.                         }
  45.                     }
  46.                     else
  47.                     {
  48.                         Console.WriteLine($"{i} performed harakiri");
  49.                         if (snowmen.Count == 0 || snowmen.Count == 1)
  50.                         {
  51.                             return;
  52.                         }
  53.                         break;
  54.                     }
  55.                    
  56.                     if (i == snowmen.Count - 1)
  57.                     {
  58.                         if (snowmen.Count == winers.Count)
  59.                         {
  60.                             count++;
  61.                         }
  62.                     }
  63.                 }
  64.                
  65.                 snowmen = winers.ToList();
  66.                 winers.Clear();
  67.                 if (snowmen.Count == 0 || snowmen.Count == 1)
  68.                 {
  69.                     break;
  70.                 }
  71.             }
  72.           }
  73.         }
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement