kvadrat4o

HornetAsault

Jul 7th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 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 HornetAssault
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var beehives = Console.ReadLine().Split(new [] {' '},StringSplitOptions.RemoveEmptyEntries).Select(a => long.Parse(a)).ToList();
  14.             var hornets = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(a => long.Parse(a)).ToList();
  15.             HornetVsBees(beehives, hornets);
  16.             PrintWinner(beehives,hornets);
  17.         }
  18.  
  19.         private static void PrintWinner(List<long> beehives, List<long> hornets)
  20.         {
  21.             Console.WriteLine(beehives.Any() ? string.Join(" ", beehives) : string.Join(" ", hornets));
  22.         }
  23.         private static void HornetVsBees(List<long> beehives, List<long> hornets)
  24.         {
  25.             for (int i = beehives.Count - 1; i >= 0; i--)
  26.             {
  27.  
  28.                 if (hornets.Sum() > beehives[beehives.Count - 1 - i])
  29.                 {
  30.                     beehives.Remove(beehives[beehives.Count - 1 - i]);
  31.                 }
  32.                 else if (hornets.Sum() < beehives[beehives.Count - 1 - i])
  33.                 {
  34.                     beehives[beehives.Count - 1 - i] -= hornets.Sum();
  35.                     hornets.Remove(hornets[0]);
  36.                     if (hornets.Count == 0)
  37.                     {
  38.                         break;
  39.                     }
  40.                 }
  41.                 else if (hornets.Sum() == beehives[beehives.Count - 1 - i])
  42.                 {
  43.                     beehives.Remove(beehives[beehives.Count - 1 - i]);
  44.                     hornets.Remove(hornets[0]);
  45.                     if (hornets.Count == 0)
  46.                     {
  47.                         break;
  48.                     }
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment