Advertisement
Spiderbait90

Untitled

Apr 9th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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 Practice
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var plants = Console.ReadLine()
  14.                 .Split()
  15.                 .Select(int.Parse)
  16.                 .ToArray();
  17.             var alive = 0;
  18.             var death = 0;
  19.             var days = 0;
  20.             for (int season = 0; season < int.MaxValue; season++)
  21.             {
  22.                 for (int day = 0; day < plants.Length; day++)
  23.                 {
  24.                     if (plants[day] > 0)
  25.                         plants[day]++;
  26.                     for (int plant = 0; plant < plants.Length; plant++)
  27.                     {
  28.                         plants[plant]--;
  29.                     }
  30.                     for (int checkAlive = 0; checkAlive < plants.Length; checkAlive++)
  31.                     {
  32.                         if (plants[checkAlive] > 0)
  33.                             alive++;
  34.                         else if (plants[checkAlive] <= 0)
  35.                             death++;
  36.                     }
  37.                     days++;
  38.                     if (alive == 0)
  39.                     {
  40.                         Console.WriteLine($"survived {days} days ({season} seasons)");
  41.                         return;
  42.                     }
  43.                     alive = 0;
  44.                     death = 0;
  45.                 }
  46.                 for (int bloom = 0; bloom < plants.Length; bloom++)
  47.                 {
  48.                     if (plants[bloom] > 0)
  49.                         plants[bloom]++;
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement