Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace P02.BakingRush
- {
- using System;
- using System.Linq;
- public class BakingRush
- {
- public static void Main()
- {
- string[] eventsOfDay = Console.ReadLine().ToLower().Split('|').ToArray();
- int startingEnergy = 100;
- int startingCoins = 100;
- bool areAllEventsDone = false;
- for (int currentAction = 0; currentAction < eventsOfDay.Length; currentAction++)
- {
- string[] currentEvent = eventsOfDay[currentAction].ToLower().Split('-').ToArray();
- if (currentEvent[0] == "rest")
- {
- int energyGain = int.Parse(currentEvent[1]);
- if (startingEnergy == 100)
- {
- Console.WriteLine("You gained 0 energy.");
- Console.WriteLine("Current energy: 100.");
- }
- else if (startingEnergy < 100 && startingEnergy + energyGain <= 100)
- {
- startingEnergy += energyGain;
- Console.WriteLine($"You gained {energyGain} energy.");
- Console.WriteLine($"Current energy: {startingEnergy}.");
- }
- else if (startingEnergy < 100 && startingEnergy + energyGain > 100)
- {
- Console.WriteLine($"You gained {100 - startingEnergy} energy.");
- Console.WriteLine($"Current energy: 100.");
- startingEnergy = 100;
- }
- }
- else if (currentEvent[0] == "order")
- {
- int coinsGained = int.Parse(currentEvent[1]);
- if (startingEnergy - 30 >= 0)
- {
- startingEnergy -= 30;
- startingCoins += coinsGained;
- Console.WriteLine($"You earned {coinsGained} coins.");
- }
- else
- {
- startingEnergy += 50;
- Console.WriteLine("You had to rest!");
- }
- }
- else
- {
- int ingredientCost = int.Parse(currentEvent[1]);
- if (startingCoins > 0 && startingCoins > ingredientCost)
- {
- Console.WriteLine($"You bought {currentEvent[0]}.");
- startingCoins -= ingredientCost;
- }
- else
- {
- Console.WriteLine($"Closed! Cannot afford {currentEvent[0]}.");
- break;
- }
- }
- if (currentAction == eventsOfDay.Length - 1)
- {
- areAllEventsDone = true;
- }
- }
- if (areAllEventsDone == true)
- {
- Console.WriteLine($"Day completed!\n" +
- $"Coins: {startingCoins}\n" +
- $"Energy: {startingEnergy}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment