Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02_BakingRush
- {
- class Program
- {
- public static void Main()
- {
- int energy = 100;
- int coins = 100;
- bool dayCompleted = true;
- List<string> dayEvent = Console.ReadLine()
- .Split('|', '-')
- .ToList();
- for (int i = 0; i <= dayEvent.Count; i++)
- {
- List<string> command = dayEvent.Take(i).ToList();
- if (i > 0)
- {
- if (command[i - 1] == "rest")
- {
- int amountToAdd = int.Parse(dayEvent[i]);
- if (energy + amountToAdd <= 100 && amountToAdd > 0)
- {
- energy += amountToAdd;
- Console.WriteLine($"You gained {amountToAdd} energy.");
- }
- else
- {
- Console.WriteLine($"You gained 0 energy.");
- }
- Console.WriteLine($"Current energy: {energy}.");
- }
- else if (command[i - 1] == "order")
- {
- int amountToAdd = int.Parse(dayEvent[i]);
- if (energy >= 30 && amountToAdd > 0)
- {
- energy -= 30;
- coins += amountToAdd;
- Console.WriteLine($"You earned {amountToAdd} coins.");
- }
- else
- {
- energy += 50;
- Console.WriteLine($"You had to rest!");
- }
- }
- else
- {
- int number = 0;
- bool isNumber = int.TryParse(command[i - 1], out number);
- if (!isNumber)
- {
- int amountToAdd = int.Parse(dayEvent[i]);
- coins -= amountToAdd;
- if (coins >= 0 && amountToAdd > 0)
- {
- Console.WriteLine($"You bought {command[i-1]}.");
- }
- else
- {
- Console.WriteLine($"Closed! Cannot afford {command[i - 1]}.");
- dayCompleted = false;
- break;
- }
- }
- }
- }
- }
- if (dayCompleted)
- {
- Console.WriteLine("Day completed!");
- Console.WriteLine($"Coins: {coins}");
- Console.WriteLine($"Energy: {energy}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement