#K70687. Animal Shelter Simulation
Animal Shelter Simulation
Animal Shelter Simulation
This problem requires you to simulate an animal shelter which holds only dogs and cats. Every animal entering the shelter is assigned a sequential order. The shelter supports the following operations:
- enqueue <species> <name>: Add an animal (either "dog" or "cat") with the given name to the shelter.
- dequeueAny: Adopt the animal that has been in the shelter for the longest time, regardless of species.
- dequeueDog: Adopt the dog that has been in the shelter for the longest time.
- dequeueCat: Adopt the cat that has been in the shelter for the longest time.
If a dequeue operation is requested and no animal of the requested type is available, output "No animals available". The input commands are processed sequentially until the command "end" is encountered.
Note: If there are multiple dequeue operations, print each output on a separate line.
inputFormat
The input consists of several lines. Each line is a command which can be one of the following:
- enqueue - To add an animal to the shelter. is either 'dog' or 'cat'.
- dequeueAny - To adopt the oldest animal available.
- dequeueDog - To adopt the oldest dog available.
- dequeueCat - To adopt the oldest cat available.
- end - To indicate the end of input.
Commands are provided via standard input (stdin).
outputFormat
For each dequeue operation (i.e., dequeueAny, dequeueDog, dequeueCat), output the name of the animal adopted on a separate line. If no animal is available for a dequeue operation, output "No animals available". The output should be written to standard output (stdout).## sample
enqueue dog Max
enqueue cat Whiskers
enqueue dog Buddy
dequeueAny
enqueue cat Fluffy
dequeueDog
dequeueCat
dequeueAny
end
Max
Buddy
Whiskers
Fluffy
</p>