← 返回 stripe 的题目列表Email Log Processing / Grouping and Sorting
类型:online_judge
Problem: Email Log Processing (Grouping + Rule-based Sorting)
You are given a list of email event logs logs. Each log is a single line string in the format:
<timestamp> <sender_email> <receiver_email> <subject>
timestamp: a non-negative integer (seconds since epoch)
sender_email, receiver_email: strings without spaces
subject: the remainder of the line starting from the 4th token; it may contain spaces (and may be empty)
Your task is to group logs by sender_email, sort each group by specific rules, and print the result.
Rules
Group by sender_email.
Within the same sender_email, sort logs by:
timestamp ascending
if equal, receiver_email lexicographically ascending
if still equal, subject lexicographically ascending
Output sender groups in lexicographical order of sender_email.
Input
Line 1: integer n, number of logs.
Next n lines: one log per line.
Output
For each sender, print:
sender: <sender_email>
Then print each sorted log line as:
<timestamp> <receiver_email> <subject>
Note: sender_email is not printed on the log lines.
Constraints
1 <= n <= 2 * 10^5
0 <= timestamp <= 10^9
Each line length <= 300
Example
Input
5
100 alice@a.com bob@b.com hello
90 alice@a.com carl@c.com meeting notes
90 dan@d.com e@e.com hi
90 alice@a.com bob@b.com a-subject
100 dan@d.com a@a.com ping
Output
sender: alice@a.com
90 bob@b.com a-subject
90 carl@c.com meeting notes
100 bob@b.com hello
sender: dan@d.com
90 e@e.com hi
100 a@a.com ping
Example
Input
1
0 a@a.com b@b.com hi
Output
sender: a@a.com
0 b@b.com hi