#K6661. User Activity Summary
User Activity Summary
User Activity Summary
In this problem, you are given a log of user events. Each event is represented by a triplet (userName, eventType, timestamp). Your task is to summarize the activities of each user. For every user, count how many times each event type occurs. The summary for each user must show the user name first, followed by event type and the corresponding count, arranged in lexicographical order by the event type. Additionally, the final output should list all users in lexicographical order by their names.
More formally, if there are ( n ) events and each event is given as: [ (user, event, timestamp) ] then for each user, let ( c_{user, event} ) represent the number of occurrences of that event. The output should be formatted so that for each user, you print a line starting with the user name, followed by pairs ( event ) and ( c_{user, event} ) for all events in sorted order.
Note: The timestamp provided in the input is not used for ordering or counting; it is just an extra piece of data.
inputFormat
The first line of input contains a single integer ( n ) which is the number of events. This is followed by ( n ) lines. Each of these lines contains a string ( userName ), a string ( eventType ), and an integer ( timestamp ) separated by spaces.
For example:
6 Alice login 5 Bob play 10 Alice play 15 Alice logout 20 Bob login 30 Alice login 35
outputFormat
For each distinct user in the input, output a single line. Each line starts with the user name, followed by pairs of event types and their corresponding counts. For each user, the event types must be output in lexicographical order. The overall order of the lines should be sorted lexicographically by the user names.
For example, the output corresponding to the sample above is:
Alice login 2 logout 1 play 1 Bob login 1 play 1## sample
6
Alice login 5
Bob play 10
Alice play 15
Alice logout 20
Bob login 30
Alice login 35
Alice login 2 logout 1 play 1
Bob login 1 play 1
</p>