Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace PowerPlants
- {
- using System;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- int[] powerPlants = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int currentDay = -1;
- int currentSeason = 0;
- bool thereIsPlantAlive = false;
- while (true)
- {
- currentDay++;
- int currIndex = currentDay % powerPlants.Length;
- thereIsPlantAlive = ManipulateThePlants(powerPlants, currIndex, -1);
- if (!thereIsPlantAlive)
- {
- break;
- }
- if (currIndex + 1 == powerPlants.Length)
- {
- currentSeason++;
- ManipulateThePlants(powerPlants, int.MinValue, +1);
- }
- }
- Console.WriteLine($"survived {currentDay + 1} days ({currentSeason} seasons)");
- }
- private static bool ManipulateThePlants(int[] powerPlants, int currentDay, int bloomPower)
- {
- bool thereIsPlantAlive = false;
- for (int currPlant = 0; currPlant < powerPlants.Length; currPlant++)
- {
- if (powerPlants[currPlant] == 0)
- {
- continue;
- }
- if (currPlant == currentDay)
- {
- thereIsPlantAlive = true;
- continue;
- }
- powerPlants[currPlant] += bloomPower;
- if (powerPlants[currPlant] > 0)
- {
- thereIsPlantAlive = true;
- }
- }
- return thereIsPlantAlive;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement