Задача Bread Factory - Demo Exam - Technology Fundamentals - Java
Колеги два дена се мъча с тая задача , нещо много забих може ли някой да я погледне да каже какво се случва дава ми 70/100.
Решение: https://pastebin.com/H66p7AbM
Условие:
You have initial energy 100 and initial coins 100. You will be given a string, representing the working day events. Each event is separated with '|' (vertical bar): "event1|event2|event3…"
Each event contains event name or item and a number, separated by dash("{event/ingredient}-{number}")
- If the event is "rest": you gain energy, the number in the second part. But your energy cannot exceed your initial energy (100). Print: "You gained {0} energy.".
After that, print your current energy: "Current energy: {0}.".
- If the event is "order": You've earned some coins, the number in the second part. Each time you get an order, your energy decreases with 30 points.
- If you have energy to complete the order, print: "You earned {0} coins.".
- If your energy drops below 0, you skip the order and gain 50 energy points. Print: "You had to rest!".
- In any other case you are having an ingredient, you have to buy. The second part of the event, contains the coins you have to spent and remove from your coins.
- If you are not bankrupt (coins <= 0) you've bought the ingredient successfully, and you should print ("You bought {ingredient}.")
- If you went bankrupt, print "Closed! Cannot afford {ingredient}." and your bakery rush is over.
If you managed to handle all events through the day, print on the next three lines:
"Day completed!", "Coins: {coins}", "Energy: {energy}".
Input / Constraints
You receive a string, representing the working day events, separated with '|' (vertical bar): " event1|event2|event3…".
Each event contains event name or ingredient and a number, separated by dash("{event/ingredient}-{number}")
Output
Print the corresponding messages, described above.
Examples
Input |
Output |
rest-2|order-10|eggs-100|rest-10 |
You gained 0 energy. Current energy: 100. You earned 10 coins. You bought eggs. You gained 10 energy. Current energy: 80. Day completed! Coins: 10 Energy: 80 |
Input |
Output |
order-10|order-10|order-10|flour-100|order-100|oven-100|order-1000 |
You earned 10 coins. You earned 10 coins. You earned 10 coins. You bought flour. You had to rest! Closed! Cannot afford oven. |
Линк към Judge: https://judge.softuni.bg/Contests/Practice/Index/1579#1
Благодаря, колега. Оказа се, че кода ми върви, прото не бях форматирал
, а го бях копирал от примера. И то всеки път печата едно и също....Тцтц дано не правя такива грешки на изпита.
Все пак благодаря, защото ако не го беше опростил нямаще да си видя грешката!