#K92197. Animal Shelter Management

    ID: 38144 Type: Default 1000ms 256MiB

Animal Shelter Management

Animal Shelter Management

Implement an animal shelter system that supports four operations:

  • enqueue: Add an animal with a given name and type (either dog or cat).
  • dequeueAny: Remove and return the name of the animal that has been in the shelter the longest, regardless of type.
  • dequeueDog: Remove and return the name of the dog that has been in the shelter the longest.
  • dequeueCat: Remove and return the name of the cat that has been in the shelter the longest.

If no animal is available for a dequeue operation, output the message \(No\ animals\ available\). The operations must follow a strict FIFO (first in, first out) ordering across all enqueued animals.

The input will be provided via stdin and the output should be sent to stdout.

inputFormat

The first line contains an integer (N) denoting the number of operations. Each of the following (N) lines contains a command, which can be one of the following:

  • enqueue name type — where name is a string representing the animal's name and type is either "dog" or "cat".
  • dequeueAny
  • dequeueDog
  • dequeueCat
Only the dequeue commands produce output.

outputFormat

For each dequeue command (dequeueAny, dequeueDog, or dequeueCat), output the name of the animal removed from the shelter on a new line. If the requested animal type is not available, output "No animals available".## sample

6
enqueue Sparky dog
enqueue Whiskers cat
dequeueAny
enqueue Fido dog
dequeueDog
dequeueCat
Sparky

Fido Whiskers

</p>