A firmware-rollout server keeps a roster of devices that registered for an update, listed in the exact order in which they registered. After a device registers, the server may ping it any number of times (including zero); every ping is logged as either acknowledged or missed.
For each registered device, compute its acknowledgement rate: the number of acknowledged pings sent to it divided by the total number of pings sent to it, rounded to exactly two decimal places. A device that was never pinged has a rate of 0.00. Report the rate for every registered device, in the order it registered.
Line 1: two integers n and m — the number of registered devices and the number of logged pings.
Each of the next n lines contains a single integer device_id: the roster, in registration order. All n device ids are distinct.
Each of the next m lines contains two space-separated tokens device_id status, where status is exactly the string ACK (acknowledged) or MISS (missed). Every device_id that appears here also appears in the roster.
n lines, one per device, in the roster's registration order. Each line contains device_id, a single space, and the device's acknowledgement rate formatted with exactly two digits after the decimal point.
Example 1
Input
3 5 101 102 103 101 ACK 101 ACK 101 MISS 102 ACK 102 MISS
Expected
101 0.67 102 0.50 103 0.00
Explanation
Device 101 received 3 pings (2 ACK, 1 MISS): rate = 2/3 = 0.6666... which rounds to 0.67. Device 102 received 2 pings (1 ACK, 1 MISS): rate = 1/2 = 0.50. Device 103 received no pings, so its rate is 0.00. Devices are printed in registration order: 101, 102, 103.
Example 2
Input
2 3 7 8 7 MISS 7 MISS 8 ACK
Expected
7 0.00 8 1.00
Explanation
Device 7 received 2 pings, both MISS, so its rate is 0/2 = 0.00. Device 8 received 1 ping, which was ACK, so its rate is 1/1 = 1.00.
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 →