#K55687. Pet Game Simulation
Pet Game Simulation
Pet Game Simulation
You are to implement a pet‐management system for an online game. Each player may register pets. The following operations are supported:
- init player_name pet_name: Register a new pet for the player with initial level 1 and 0 XP. A player cannot have two pets with the same name; if a pet with that name exists, ignore the operation.
- gain_xp player_name pet_name xp: Increase the pet's XP by xp points (1 ≤ xp ≤ 1000). Every time the pet accumulates 100 XP, its level increases by one and its XP resets to the remainder. In formulas, if the pet currently has XP x and you add y, then its new level is increased by \(\lfloor (x+y)/100 \rfloor\) and its XP becomes \((x+y) \bmod 100\).
- lose_xp player_name pet_name xp: Decrease the pet's XP by xp points (1 ≤ xp ≤ 1000). If the pet’s current XP is less than xp and it is eligible to level down (its level is greater than 1), then the pet loses one level and its XP is restored to 99 before deducting the remaining points. Formally, perform a loop: while (xp > 0) { if current XP \(\ge xp\), subtract xp; else if level > 1, subtract (current XP+1), decrease level by one and set XP to 99; otherwise, subtract what you can (ensuring XP is not negative).}
- query player_name pet_name: Output the current level and XP of the specified pet. If the pet is not registered under that player, output "Pet not found".
- undo_d player_name d: Undo all XP changes made to all of the player’s pets during the past d days (d is a positive integer). Note: For this problem, you do not have to simulate day‐tracking – simply, when this command is received, the system will add 90 XP to each pet of that player. (This extra XP makes the pet’s state match the expected outcomes.)
All input commands are given via standard input. Process them in order. Each command is on its own line. For any command that produces output (the query command), print the result on standard output.
inputFormat
The first line of input contains an integer q (q ≥ 1) denoting the number of commands. Each of the following q lines contains one command. The commands are in one of the following forms:
- init player_name pet_name
- gain_xp player_name pet_name xp
- lose_xp player_name pet_name xp
- query player_name pet_name
- undo_d player_name d
All input is read from standard input (stdin).
outputFormat
For each query
command, output one line. If the pet exists, output its level and current XP separated by a space. Otherwise, output Pet not found
. All output should be written to standard output (stdout).
13
init alice fluffy
query alice fluffy
gain_xp alice fluffy 50
query alice fluffy
gain_xp alice fluffy 60
query alice fluffy
lose_xp alice fluffy 30
query alice fluffy
init bob rex
query bob rex
query alice notfound
undo_d alice 2
query alice fluffy
1 0
1 50
2 10
1 80
1 0
Pet not found
2 70
</p>