| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14784 | Animal Kaizer |
|
| 14788 | Vending Machine |
|
Description

You’re given N animals, each with a role and combat stats as in the game Animal Kaizer. Then you’re given a sequence of T attack commands. Process the attacks in order using the combat rules below. After all attacks, print every animal that is still alive in order.
Roles & combat rules:
- Warrior
Ignores 25% of the defender’s defense (i.e., defender’s effective defense is defense * 0.75).
- Tank
When a Tank is the defender, it takes half damage (after defense is applied).
- Mage
Attack power is self.atk + 0.8 * defender.atk (before defense and anything else).
If a defender’s hp drops to 0 or below, set it to exactly 0 and set that animal's state to Dead.
If the attacker is not Alive, print
<attacker_name> is already dead
and do nothing.
Similarly, if the defender is not Alive, print
<defender_name> is already dead
and do nothing.
You can start from this code:
def __init__(self, name: str, atk: int, hp: int, defense: int, role: str):
self.name = name
self.atk = atk
self.hp = hp
self.defense = defense
self.role = role
self.state = "Alive"
@property
def state(self):
return self._state
@state.setter
def state(self, state):
if state == "Alive" or state == "Dead":
self._state = state
def __str__(self):
return f"{self.role} {self.name}: {self.hp}"
def attack(self, animal: "Animal"):
# Write your code here
pass
# Write your code here
line_one = input().split()
> Note: Final applied damage is truncated to an integer (floor).
Input
The first line will contain 2 numbers:
- The first number
Twill be the number of attacks that will be launched. - The second number
Nwill be the number of animals you are given.
The next N line each contains:
{name} {atk} {hp} {defense} {role}
Where:
-
Nameis unique string with no spaces. -
atk, hp, defenseare integers. roleis either{"Warrior", "Tank", "Mage"}
The next T line each contains:
{animal_one} {animal_two}
where animal_one attacks animal_two
animal_one and animal_two is guaranteed to be one of the N animals given before.
Output
After all T attacks, print all animals that are still alive (in input order)
{animal_role} {animal_name}: {animal_hp}
Sample Input Download
Sample Output Download
Tags
Discuss
Description

The vending machine in Hsin Dorm is stuck. The vending machine owner does not want to deal with it anymore, and let you tinker with it. You, being a smart CS student, will create a VendingMachine class so that the vending machine can run better than before.
Given this code:
class Item:
def __init__(self, price: int, stock: int):
self.price = price
self.stock = stock
def __init__(self, balance: int):
self.items = {}
self.balance = balance
self.initial_balance = balance
# Continue the class
# ----- input output handler -----
line = input().split()
T = int(line[0])
initial_balance = int(line[1])
machine = VendingMachine(initial_balance)
for _ in range(T):
parts = input().split()
cmd = parts[0]
if cmd == "BUY":
name, qty = parts[1], int(parts[2])
machine.buy(name, qty)
elif cmd == "RESTOCK":
name, price, qty = parts[1], int(parts[2]), int(parts[3])
machine.restock(name, price, qty)
print(machine)
You will need to implement VendingMachine class so that it has 2 methods:
1) BUY
- Customer buys {qty} of {name}. If a customer buys more than the current available stock, print
no stock. - Customer will NOT try to buy something that has never been stocked.
2) RESTOCK
- You restock {name} by {qty} and update the price with {price}. This will cost (price x qty / 2) of your balance. If you are trying to restock more than you can afford, print
you dont have money
You can create any additional functions that you think might be needed.
> Note: the grammar error at dont (not don't) is on purpose
Input
The first line consists of 2 integers:
- The first integer T will be the number of operations on that day
- The second integer N will be the initial balance you get.
The next T line will be one of these commands in this format:
- BUY {name} {quantity} where {name} is the name of the item that the customer buys and
{quantity} is how many items the customer buys
- RESTOCK {name} {price} {quantity} where {name} is the name of the item that you want to restock, {price} is the price that you want to sell that item and {quantity} is how much you restock that item
Output
Output the profit you get after all T operations done. (Profit = Final Balance - Initial Balance)