Monster roster
Find the monster with the most hit points in a roster of up to eight, which the starter reads into roster, an array of structures. Each input line is a name of up to five letters, the monster's hit points, and its attitude, for example Troll 88 -35. Print the monster with the most hit points in this form:
strongest: Troll, 88 hp, attitude -35
If two monsters tie, the one listed first wins. If the roster has no monsters, print the roster is empty instead.
A structure (a struct in C) is a group of fields stored side by side, each at a fixed distance, its offset, from the start of the structure. The starter names the offsets: the name at 0, the attitude at 6, the hit points at 8, and each monster takes 12 bytes, so monster i starts at roster + i * 12. Load each field with its own size. The attitude is a signed halfword (16 bits): a 32-bit load at its offset would also pick up two bytes of the hit points, and an unsigned load turns -35 into 65501.
What is checked
- one line naming the strongest monster, or the empty-roster line
- the program exits cleanly
- the attitude is loaded as a signed halfword (
ldrshpresent) - your program also runs on rosters you do not see: a tie, a single monster, an empty roster, the strongest listed last, and a roster where every monster has negative hit points
specification
ldrshWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.