Advertisement
Guest User

Power Plants

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