#K95197. Loyalty Stamp Tracker
Loyalty Stamp Tracker
Loyalty Stamp Tracker
In this problem you are required to simulate a loyalty card system for a record store. Each time a customer makes a purchase (always a 'buy' transaction), they receive a stamp on their loyalty card. When a customer collects 10 stamps, they are awarded a free album and their stamp count resets to zero. Formally, if a customer’s stamp count reaches $$10$$, then the number of free albums is increased by one and the stamp count resets to $$0$$.
Your task is to process a list of transactions, and then output for each customer the number of stamps remaining and the number of free albums they have earned. The customers in the output must be listed in lexicographical order.
Example:
If the transactions are:
Alice buy Bob buy Alice buy
Then the output should be:
{"Alice":{"free_albums":0,"stamps":2},"Bob":{"free_albums":0,"stamps":1}}
inputFormat
The first line of input contains a single integer $$N$$ representing the number of transactions. Each of the next $$N$$ lines contains two space-separated strings: the customer's name and a transaction type. In this problem, the only valid transaction type is buy
.
outputFormat
Output a JSON object (printed as a single line) representing the result. The object’s keys are customer names (sorted in lexicographical order), and each associated value is another JSON object with two keys: stamps
(the remaining number of stamps) and free_albums
(the number of free albums earned).
3
Alice buy
Bob buy
Alice buy
{"Alice":{"free_albums":0,"stamps":2},"Bob":{"free_albums":0,"stamps":1}}