Advertisement
Aborigenius

PowerPlants

Jun 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 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 PowerPlants
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] plantsLife = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int currentDay = 0;
  15.             int seasonDays = plantsLife.Length;
  16.             while (ArrayPlantsLife(plantsLife))
  17.             {
  18.  
  19.                 for (int cnt = 0; cnt < plantsLife.Length; cnt++)
  20.                 {
  21.                     if (plantsLife[cnt] == 0)
  22.                     {
  23.                         continue;
  24.                     }
  25.                     if ((currentDay % seasonDays) != cnt)
  26.                     {
  27.                         plantsLife[cnt]--;
  28.                     }
  29.                  
  30.                 }
  31.                 currentDay++;
  32.                 if (currentDay % seasonDays == 0)
  33.                 {
  34.                     for (int k = 0; k < plantsLife.Length; k++)
  35.                     {
  36.                         if (plantsLife[k] != 0)
  37.                         {
  38.                             plantsLife[k]++;
  39.                         }
  40.                     }
  41.                 }
  42.  
  43.             }
  44.             int seasons = (currentDay -1) / seasonDays;
  45.             string FU = String.Empty;
  46.             if (seasons == 1)
  47.             {
  48.                 FU = "season";
  49.             }
  50.             else
  51.             {
  52.                 FU = "seasons";
  53.             }
  54.  
  55.             Console.WriteLine($"survived {currentDay} days ({seasons} {FU})");
  56.         }
  57.         static bool ArrayPlantsLife(int[] plantsLife)
  58.         {
  59.             for (int cnt = 0; cnt < plantsLife.Length; cnt++)
  60.             {
  61.                 if (plantsLife[cnt] > 0)
  62.                 {
  63.                     return true;
  64.                 }
  65.             }
  66.             return false;
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement