elena1234

CounterStrike

Oct 11th, 2020 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace CounterStrike
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main()
  8.         {
  9.             int energy = int.Parse(Console.ReadLine());
  10.             int countOfBattles = 0;
  11.  
  12.             string command = string.Empty;
  13.             while((command=Console.ReadLine())!="End of battle")
  14.             {
  15.                 int distanceEqualToEnergy = int.Parse(command);
  16.                 if (energy >= distanceEqualToEnergy)
  17.                 {
  18.                     energy -= distanceEqualToEnergy;
  19.                     countOfBattles++;
  20.                 }
  21.  
  22.                else if (energy < distanceEqualToEnergy)
  23.                 {
  24.                     Console.WriteLine($"Not enough energy! Game ends with {countOfBattles} won battles and {energy} energy");
  25.                     return;
  26.                 }
  27.  
  28.                 if (countOfBattles % 3 == 0)
  29.                 {
  30.                     energy += countOfBattles;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine($"Won battles: {countOfBattles}. Energy left: {energy}");
  35.         }
  36.       }
  37.     }
  38.  
  39.  
  40.  
Add Comment
Please, Sign In to add comment