simeon3000

Power Plants

Jun 21st, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1.             int[] plants = Console.ReadLine().Split().Select(int.Parse).ToArray();
  2.  
  3.             int daysSurvived = 0;
  4.             int season = 0;
  5.             int power = 0;
  6.  
  7.             while (true)
  8.             {
  9.                 for (int i = 0; i < plants.Length; i++)
  10.                 {
  11.                     power = 0;
  12.                     daysSurvived++;
  13.  
  14.                     for (int j = 0; j < plants.Length; j++)
  15.                     {
  16.                         if (i == j)
  17.                         {
  18.                             if (plants[i] > 0)
  19.                             {
  20.                                 plants[i]++;
  21.                             }
  22.                         }
  23.  
  24.                         if (plants[j] > 0)
  25.                         {
  26.                             plants[j]--;
  27.                         }
  28.  
  29.                         power += plants[j];
  30.                     }
  31.  
  32.                     if (power > 0) continue;
  33.                     else break;
  34.  
  35.                 }
  36.  
  37.                 if (power > 0)
  38.                 {
  39.                     season++;
  40.  
  41.                     for (int i = 0; i < plants.Length; i++)
  42.                     {
  43.                         if (plants[i] > 0)
  44.                         {
  45.                             plants[i]++;
  46.                         }
  47.                     }
  48.                 }
  49.  
  50.                 else break;
  51.  
  52.             }
  53.  
  54.             Console.WriteLine($"survived {daysSurvived} days ({season} seasons)");
Advertisement
Add Comment
Please, Sign In to add comment