[Virtual machine] Email Thread Thread Yemeir


While creating a super awesome email client, the administrator encounters a problem: how to keep track of email threads? The established methods of matching subject line or tracking a unique identifier seemed unreliable, so there is a new approach. The email body is compared to previously mails and if there is a match, it will be marked as part of the thread.

The reply will always be in front of the previously sent mails and separated by "---" from rest of the mail. A user will never use this special token in the body of an email. Emails are given in order they were sent, and each email contains 3 fields: the sender, the receiver and the mail body. A thread will always consists of the same two people and replies will be in format as described earlier.

Help the administrator to create proper email threads. For each email, determine the thread id and email number in that thread.

Take for example, n = 3 emails given by emails = [('[email protected]', '[email protected]', 'Are you back from vacation?'), ('[email protected]', '[email protected]'; 'did you get the key?'), ('[email protected]', '[email protected]', 'Just got in.---Are you back from vocation?')].
There are two threads in the emails. The return array should be a two dimensional array where each element consists of two integers: the email thread id and the position within the thread, so in this case, the output should be [(1, 1), (2, 1), (1, 2)] This signifies that the first email is in thread 1 and its position is 1, the second email is in thread 2 and its position in that thread is 1, and the third email is in the thread 1, position 2.

Function Description
Complete the function getErnailThreads in the editor below. The function must return a 2D array.

getEmailThreads has the following parameter(s):
ernails [emails(0),...emails(n-1)]: an array of strings

Constraints
• 1 ≤ n ≤ 700
• The maximum length of a mail won't exceed 200
• The email body will contain only lowercase English letters, blank space, comma, period and question mark.
• The email of a person will comprise of lowercase English letters, at the rate (@) sign, and period.


Sample Input For Custom Testing
3
[email protected], [email protected], hello x, how are you?
[email protected], [email protected], did you take a look at the event?
[email protected], [email protected], i am great. how are you?---hello x, how are you?

Sample Output
1 1
2 1
1 2

 

Meaning of the questions:

Ideas:

Code:

Guess you like

Origin www.cnblogs.com/liuliu5151/p/11513107.html