A mountaintop observatory logs every calibration pass its night-shift astronomers run on the facility's shared telescope instruments. You are given the roster of astronomers, the catalogue of instruments, and a log of completed calibration passes. For every astronomer and every instrument, report how many times that astronomer completed a calibration pass on that instrument.
n, m, and k — the number of astronomers on the roster, the number of instruments in the catalogue, and the number of calibration-pass log entries.n lines each contain an integer id and a string name — one astronomer's unique id and name.m lines each contain a single string instrument — one instrument's unique name.k lines each contain an integer astronomerId and a string instrument — one completed calibration pass by that astronomer on that instrument. The same (astronomerId, instrument) pair may appear more than once in the log.Print exactly n * m lines, one for every (astronomer, instrument) pair, ordered first by ascending astronomer id and then by instrument name in ascending lexicographic (ASCII) order. Each line contains, space-separated: the astronomer's id, the astronomer's name, the instrument's name, and the number of calibration passes that astronomer completed on that instrument (0 if none).
astronomerId appearing in the log is one of the n roster ids, and every instrument appearing in the log is one of the m catalogue namesExample 1
Input
2 2 3 1 Vega 2 Orion Spectrometer Photometer 1 Spectrometer 1 Spectrometer 2 Photometer
Expected
1 Vega Photometer 0 1 Vega Spectrometer 2 2 Orion Photometer 1 2 Orion Spectrometer 0
Explanation
Astronomer 1 (Vega) logged two calibration passes on Spectrometer and none on Photometer; astronomer 2 (Orion) logged one pass on Photometer and none on Spectrometer. Sorted by ascending astronomer id and then by instrument name (Photometer comes before Spectrometer alphabetically), the output lists Vega's Photometer count (0), Vega's Spectrometer count (2), Orion's Photometer count (1), then Orion's Spectrometer count (0).
Example 2
Input
1 1 0 5 Lyra Radar
Expected
5 Lyra Radar 0
Explanation
There is only one astronomer (id 5, Lyra) and one instrument (Radar), and the log is empty, so the single output line reports a count of 0 calibration passes for that pair.
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 →