#C2829. Mythical Creature Manager

    ID: 46188 Type: Default 1000ms 256MiB

Mythical Creature Manager

Mythical Creature Manager

In this problem, you are given information about two types of mythical creatures: Dragons and Unicorns. A Dragon is represented by its name, fire power, and scale thickness, while a Unicorn is represented by its name, horn length, and magic power. You must read a list of creature records in JSON format from standard input, create the corresponding objects, determine the strongest creature (where the strength of a Dragon is its fire power and that of a Unicorn is its magic power), and group the creatures by type. Finally, output the name of the strongest creature, the counts for each creature type, and the names of the creatures (in the order of their appearance) for each type.

Note: If any formulas are needed, remember to format them in LaTeX. For instance, the strength of a Dragon is given by fire_power\text{fire\_power} and that of a Unicorn by magic_power\text{magic\_power}.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer (n) which represents the number of creature entries.

  • Each of the next (n) lines contains a JSON string representing one creature. The JSON object will be in one of the following forms:

    For a Dragon: {"type": "Dragon", "name": string, "fire_power": integer, "scale_thickness": integer}

    For a Unicorn: {"type": "Unicorn", "name": string, "horn_length": integer, "magic_power": integer}

Each JSON record provides all the necessary details of the creature.

outputFormat

The output should be written to standard output (stdout) and must contain exactly four lines:

  1. The first line prints the name of the strongest creature.
  2. The second line prints two integers separated by a space: the count of Dragons and the count of Unicorns.
  3. The third line prints the names of all Dragons in the order they appeared in the input, separated by a space. If there are no Dragons, output an empty line.
  4. The fourth line prints the names of all Unicorns in the order they appeared in the input, separated by a space. If there are no Unicorns, output an empty line.## sample
4
{"type": "Dragon", "name": "Smaug", "fire_power": 95, "scale_thickness": 10}
{"type": "Unicorn", "name": "Sparkle", "horn_length": 50, "magic_power": 80}
{"type": "Dragon", "name": "Fafnir", "fire_power": 100, "scale_thickness": 20}
{"type": "Unicorn", "name": "Twilight", "horn_length": 40, "magic_power": 85}
Fafnir

2 2 Smaug Fafnir Sparkle Twilight

</p>