bullit3189

Baking Rush TF MidExam 27Oct18

Jan 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02BakingRush
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = Console.ReadLine();
  11. char[] delimeter = { '|' };
  12.  
  13. string[] events = input.Split(delimeter, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15. int coins = 100;
  16. int energy = 100;
  17.  
  18. for (int i = 0; i < events.Length; i++)
  19. {
  20.  
  21. string currEvent = events[i];
  22.  
  23. string[] command = currEvent.Split('-', StringSplitOptions.RemoveEmptyEntries);
  24.  
  25. string action = command[0];
  26.  
  27. if (action == "rest")
  28. {
  29. int energyToAdd = int.Parse(command[1]);
  30. energy += energyToAdd;
  31.  
  32. if (energy >= 100)
  33. {
  34. int energyToAddDiff = energy - 100;
  35. energyToAdd = energyToAdd - energyToAddDiff;
  36. energy = 100;
  37.  
  38. }
  39. Console.WriteLine("You gained {0} energy.", energyToAdd);
  40. Console.WriteLine("Current energy: {0}.", energy);
  41.  
  42. }
  43. else if (action == "order")
  44. {
  45. int coinsToAdd = int.Parse(command[1]);
  46.  
  47.  
  48. if (energy-30 >= 0)
  49. {
  50. coins += coinsToAdd;
  51. Console.WriteLine("You earned {0} coins.", coinsToAdd);
  52. energy -= 30;
  53. }
  54. else
  55. {
  56.  
  57. energy += 50;
  58. Console.WriteLine("You had to rest!");
  59.  
  60. }
  61. }
  62. else
  63. {
  64. string ingredient = action;
  65. int price = int.Parse(command[1]);
  66.  
  67. coins -= price;
  68.  
  69. if (coins > 0)
  70. {
  71. Console.WriteLine("You bought {0}.", ingredient);
  72.  
  73. }
  74. else
  75. {
  76. Console.WriteLine("Closed! Cannot afford {0}.", ingredient);
  77. return;
  78. }
  79. }
  80. }
  81.  
  82. Console.WriteLine("Day completed!");
  83. Console.WriteLine("Coins: {0}", coins);
  84. Console.WriteLine("Energy: {0}", energy);
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment