Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02BakingRush
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- char[] delimeter = { '|' };
- string[] events = input.Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
- int coins = 100;
- int energy = 100;
- for (int i = 0; i < events.Length; i++)
- {
- string currEvent = events[i];
- string[] command = currEvent.Split('-', StringSplitOptions.RemoveEmptyEntries);
- string action = command[0];
- if (action == "rest")
- {
- int energyToAdd = int.Parse(command[1]);
- energy += energyToAdd;
- if (energy >= 100)
- {
- int energyToAddDiff = energy - 100;
- energyToAdd = energyToAdd - energyToAddDiff;
- energy = 100;
- }
- Console.WriteLine("You gained {0} energy.", energyToAdd);
- Console.WriteLine("Current energy: {0}.", energy);
- }
- else if (action == "order")
- {
- int coinsToAdd = int.Parse(command[1]);
- if (energy-30 >= 0)
- {
- coins += coinsToAdd;
- Console.WriteLine("You earned {0} coins.", coinsToAdd);
- energy -= 30;
- }
- else
- {
- energy += 50;
- Console.WriteLine("You had to rest!");
- }
- }
- else
- {
- string ingredient = action;
- int price = int.Parse(command[1]);
- coins -= price;
- if (coins > 0)
- {
- Console.WriteLine("You bought {0}.", ingredient);
- }
- else
- {
- Console.WriteLine("Closed! Cannot afford {0}.", ingredient);
- return;
- }
- }
- }
- Console.WriteLine("Day completed!");
- Console.WriteLine("Coins: {0}", coins);
- Console.WriteLine("Energy: {0}", energy);
- }
- }
- }
Add Comment
Please, Sign In to add comment