Advertisement
ElviraPetkova

2.Baking_Rush

Jan 19th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _2.Baking_Rush
  8. {
  9.     class Program
  10.     {
  11.         public static void Main()
  12.         {
  13.             int energy = 100;
  14.             int coins = 100;
  15.  
  16.             string[] arrayFromEvents = Console.ReadLine().Split('|').ToArray();
  17.             bool finishedDay = true;
  18.  
  19.             for (int i = 0; i < arrayFromEvents.Length; i++)
  20.             {
  21.                 string[] oneEvent = arrayFromEvents[i].Split('-').ToArray();
  22.                 string action = oneEvent[0];
  23.                 int counter = int.Parse(oneEvent[1]);
  24.  
  25.                 if(action == "rest")
  26.                 {
  27.                     if (energy + counter >= 100)
  28.                     {
  29.                         counter = counter - ((energy + counter) - 100);
  30.                     }
  31.  
  32.                     energy += counter;
  33.                     Console.WriteLine($"You gained {counter} energy.");
  34.                     Console.WriteLine($"Current energy: {energy}.");
  35.                 }
  36.                 else if(action == "order")
  37.                 {
  38.                     if(energy >= 30)
  39.                     {
  40.                         energy -= 30;
  41.                         coins += counter;
  42.                         Console.WriteLine($"You earned {counter} coins.");
  43.                     }
  44.                     else
  45.                     {
  46.                         energy += 50;
  47.                         Console.WriteLine("You had to rest!");
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     if (coins > counter)
  53.                     {
  54.                         coins -= counter;
  55.                         Console.WriteLine($"You bought {action}.");  
  56.                     }
  57.                     else
  58.                     {
  59.                         Console.WriteLine($"Closed! Cannot afford oven.");
  60.                         finishedDay = false;
  61.                         return;
  62.                     }
  63.                 }
  64.             }
  65.  
  66.             if(finishedDay)
  67.             {
  68.                 Console.WriteLine("Day completed!");
  69.                 Console.WriteLine($"Coins: {coins}");
  70.                 Console.WriteLine($"Energy: {energy}");
  71.             }
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement