Advertisement
optybg

Untitled

Feb 18th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace PowerPlants_6
  5. {
  6.     public class PowerPlants_6
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             var powerLevel = Console.ReadLine()
  11.                 .Split(' ')
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             var daysInSeason = powerLevel.Length;
  16.             var daysAlive = 0;
  17.  
  18.            
  19.            
  20.             for (int i = 0; i < daysInSeason-1; i++)
  21.             {
  22.                 for (int p = 0; p < powerLevel.Length; p++)
  23.                 {
  24.                     if (i!=p && powerLevel[p]!=0)
  25.                     {
  26.                         powerLevel[p] = powerLevel[p] - 1;
  27.                     }
  28.                 }
  29.  
  30.                 daysAlive++;
  31.  
  32.                 var sum = 0;
  33.                 for (int j = 0; j < powerLevel.Length; j++)
  34.                 {
  35.                     sum = sum + powerLevel[j];
  36.                 }
  37.                 if (sum == 0)
  38.                 {
  39.                     i = -1;
  40.                 }
  41.             }
  42.  
  43.             Console.WriteLine(daysAlive);
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement