Pet
InterviewTime limit1sMemory limit128 MB
Simulate feeding and exercising a pet's weight across scenarios and report whether it ends happy, sad, or dead based on simple weight thresholds.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
You are caring for a pet in a console game. Depending on its current weight, the pet is happy, sad, or dead.
Each scenario gives the pet's ideal weight o and actual weight w. After all actions in a scenario are processed, the pet is happy if its actual weight is strictly greater than half of the ideal weight and strictly less than twice the ideal weight. If the actual weight becomes 0 or less at any time, the pet dies. In every other case, the pet is sad.
You can perform two kinds of actions on the pet.
E n: exercise the pet fornminutes, decreasing its actual weight byn.F n: feed the pet byn, increasing its actual weight byn.
For every action, n is an integer from 1 to 999. If the pet dies during a scenario, the remaining actions in that scenario are still read from input, but they no longer affect the pet's weight.
Input
The input consists of several scenarios. Scenarios are numbered from 1 in the order they appear.
Each scenario starts with one line containing the ideal weight o and actual weight w (10 ≤ o, w ≤ 1000). The following lines each contain one action. An action has the form E n or F n, where 1 ≤ n ≤ 999.
A scenario ends with # 0, which must not be processed as an action. The whole input ends with 0 0, which must not be processed.
Output
For each scenario, print one line containing the scenario number and the pet's state after all actions are processed, separated by a space.
- Print
:-)if the pet is happy. - Print
:-(if the pet is sad. - Print
RIPif the pet is dead.