A community choir logs rehearsal time as a flat list of entries: each entry records one member's total practice minutes on one song section. The director wants these entries consolidated into a single attendance grid — one row per member, one column per song section — so that any gap in a member's practice log is immediately visible as a zero. Write a program that assembles this grid from the logged entries.
m — the number of logged entries.m lines contains one entry: <member> <song> <minutes>, where member and song are non-empty strings of lowercase letters and digits (at most 20 characters each), and minutes is an integer with 0 <= minutes <= 1000000. Every (member, song) pair appears at most once across all m entries.Let the songs be ordered by the position at which each song name first appears while scanning the entries from the first line to the last, and let the members be ordered the same way (by first appearance). Print 1 + (number of distinct members) lines:
0 for any (member, song) pair that never appeared in the input.Example 1
Input
4 amy alto1 30 ben tenor1 45 amy tenor1 20 ben alto1 0
Expected
alto1 tenor1 amy 30 20 ben 0 45
Explanation
Scanning the four entries in order, the first song encountered is alto1 (from amy's entry) and the second is tenor1 (from ben's entry), so the header is `alto1 tenor1`. Members appear in order amy, then ben. amy logged alto1=30 and tenor1=20, giving row `amy 30 20`. ben logged tenor1=45 and alto1=0 (explicitly zero, not missing), giving row `ben 0 45`, with the alto1 value placed first because alto1 is the first column.
Example 2
Input
1 cara solo1 12
Expected
solo1 cara 12
Explanation
With a single entry, the only song is solo1 and the only member is cara, so the output is the header `solo1` followed by the row `cara 12`.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →