提示: 欢迎访问OurACM平台。
Problem 2043 Social Network

Accept: 24    Submit: 250
Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

A social network is a social structure made up of individuals called “nodes”. There are connections between nodes. One connection between two nodes denotes a two-way relationship, in other words, each node of the two shares information with the alternative one. Of course, you need to implement such function within Zuck’s framework. Also, as Zuck’s social network is newly built, it may be incomplete, so the system may receive/send some spam message. And it is also your duty to judge whether a message is spam. In the following, Zuck would tell you the details.

You task is to implement the following operation within Zuck’s framework:

1)current_time NEW SYSTEM START

This operation indicates that Zuck’s social network starts to work at current_time. The format of current_time is [MM/DD,HH:MM], representing month, day, hour and minute respectively. Here is an example: [12/22,12:33]. In some cases, you may need to write some leading zero to satisfy such format, like [01/01,00:00] and [03/11,02:20]. Note that all the time in Zuck’s system should satisfy such format.

For such kind of operation, your task is to output:

current_time New System Started.

2)current_time "user_name" REGISTER

This operation indicates that a user register at current_time, and the registration name is user_name. Note that the user_name is within a double quotation mark. The legal user_name is a character string no longer than 16. The allowed characters are all capital letters, all low case letters and white space. Here are some legal examples: “AXBB”, “att ABDC”, “ABC abc”.

When the system receives such an operation (indicating that one user is trying to register), you should always output:

current_time user_name Registered.

However, if "user_name" has already been registered, you should ignore this operation.

3)current_time "user_name" LOGIN

This operation indicates that user “user_name” login to the system at current_time. After s/he has login to the system, the user can see his/her personal page. The user can find all the messages released by his friends and the system before s/he login. To simply the problem, we assume that the system would just send one user message when someone adds her/him to his/her friend list. When a user login to the system, you should always print the following messages:

current_time user_name Logined.

Then you should show the user’s personal page. Here is the format of one personal page:

+-----------------------------------------+ | User Name : user_name | +-----------------------------------------+ | time_1 friend_name said : friend_text | | time_2 friend_name add you as a friend. | | ... | +-----------------------------------------+

You should print a personal page strictly according to the format above. First, you need to print a headline:

+-----------------------------------------+ | User Name : user_name | +-----------------------------------------+

Then, you need to print each message in a single line with the format:

| time_1 friend_name said : friend_text |

You should always output enough white spaces to align right the ‘|’s in the right side of each line. That is, assume that one user totally receives n messages, respectively at time_1, time_2, …, time_n. We denote the string “time_i friend_name said : friend_text” as expression(i), and denote the string “User Name : user_name” as expression(0). Assume that the length of expression(i) is Len(i) and Len(j) is maximum. Then, when you need to print expression(t), here 0≤t≤n, you should first print a ‘|’followed by a space, then print the expression(t). You should still print Len(j)-Len(t)+1 white spaces followed by a ‘|’ in this line.

Finally, you should print: ‘+-----------------------------------------+‘ in a single line.

All the messages should be sorted and showed in the personal page according to some rules. In this system, we skimpily set the rule like this: if one message is sent later by another message, then the later one is prior to the earlier one, and thus should be put in the personal page before the earlier message. Here is an example:

+-------------------------------------------------+ | User Name : Zuck | +-------------------------------------------------+ | [04/01,13:50] Mary said : Today is funny! | | [04/01,12:32] Lily said : What a boring day is! | | [03/01,11:30] Lily add you as a friend. | +-------------------------------------------------+

Note that If the user has already login to the system, or an unregistered user tries to login to the system, you need not to print anything. Also we always assume that a user will read all his/her messages when s/he login to the system.

4)current_time "user_name" REFRESH

This operation indicates that user ‘user_name’ refreshes his/her personal page at time current_time. Then the user would receive all the messages that are released by his/her friends or the system before this time. Thus you need to first print the following message:

current_time user_name Refreshed.

And then reprint a refreshed personal page for the user. If the user has not login to the system, or an unregistered user tries to refresh the personal page, you should print nothing.

You may assume that every user would not refresh the personal page unless s/he has already read all his/her new messages.

5)current_time "user_name" LOGOUT

This operation indicates that user ‘user_name’ logout from the system at curret_time. You should print the following message:

current_time user_name Logout.

However, if the user has not login to system, or an unregistered user tries to logout the system, you should do nothing.

6)current_time "user_name_a" AND "user_name_b" MAKE FRIENDSHIP

This operation indicates that one connection is established between two users user_name_a and user_name_b at time curret_time. To simply the problem, you need not examine whether anyone of the two users has login before.

When this operation is done, you should always print the following message:

current_time user_name_a and user_name_b are now friends.

However, if the connection between two users has been established, or at least one of the users is unregistered, or the two user names are the same, you should ignore this operation.

7)current_time "user_name" SAYS "text"

This operation indicates that user user_name publishes the information “text”. Here, the content of the information is within a double quotation mark. The length of the content should not exceed 256, and it can be made up of digits, capital letters, low case letters, white space, underline, single quotation mark, comma, period, question mark and/or exclamation mark. Here are some legal examples: “Oh yeah!”, “Wonderful”, “ur”, “BBBBBB”.

When this operation is done by one user, you should always print the following message:

current_time user_name said : text

However, if the user has not login, or the user name has not been registered, you should ignore this operation.

8)current_time SYSTEM SHUTDOWN

This operation indicates that the system is shut down at current_time. You should print the following:

current_time System Shutdown.

When this operation is done.

Input

There are multiple test cases in this problem, you should process until EOF.

There are several lines in each test case, and each line would describe just one of the eight operations. Two consecutive test cases would be separated by a blank line. Each test case would begin with operation 1, and end with operation 8.

We ensure that all the content of user name and text is legal. In each test case, earlier operation would be showed first. Also, the number of the users of Zuck’s system would not exceed 128, and the size of the input test data would not exceed 2MB.

Output

For each test case, print a line containing the test case number (beginning with 1), and then please output right messages according to the description above.

Sample Input

[01/01,00:00] NEW SYSTEM START [01/01,01:00] "Zuck" REGISTER [01/02,12:00] "Mary" REGISTER [01/03,11:34] "Lily" REGISTER [02/03,13:44] "Zuck" AND "Lily" MAKE FRIENDSHIP [03/25,17:27] "Zuck" AND "Mary" MAKE FRIENDSHIP [04/01,12:00] "Lily" LOGIN [04/01,12:32] "Lily" SAYS "What a boring day is!" [04/01,13:00] "Mary" LOGIN [04/01,13:50] "Mary" SAYS "Today is funny!" [04/01,14:00] "Lily" LOGOUT [04/01,15:00] "Mary" LOGOUT [04/01,16:12] "Zuck" LOGIN [04/01,16:30] "Zuck" LOGOUT [04/01,23:59] SYSTEM SHUTDOWN

Sample Output

Case 1: [01/01,00:00] New System Started. [01/01,01:00] Zuck Registered. [01/02,12:00] Mary Registered. [01/03,11:34] Lily Registered. [02/03,13:44] Zuck and Lily are now friends. [03/25,17:27] Zuck and Mary are now friends. [04/01,12:00] Lily Logined. +-----------------------------------------+ | User Name : Lily | +-----------------------------------------+ | [02/03,13:44] Zuck add you as a friend. | +-----------------------------------------+ [04/01,12:32] Lily said : What a boring day is! [04/01,13:00] Mary Logined. +-----------------------------------------+ | User Name : Mary | +-----------------------------------------+ | [03/25,17:27] Zuck add you as a friend. | +-----------------------------------------+ [04/01,13:50] Mary said : Today is funny! [04/01,14:00] Lily Logout. [04/01,15:00] Mary Logout. [04/01,16:12] Zuck Logined. +-------------------------------------------------+ | User Name : Zuck | +-------------------------------------------------+ | [04/01,13:50] Mary said : Today is funny! | | [04/01,12:32] Lily said : What a boring day is! | | [03/25,17:27] Mary add you as a friend. | | [02/03,13:44] Lily add you as a friend. | +-------------------------------------------------+ [04/01,16:30] Zuck Logout. [04/01,23:59] System Shutdown.

Source

2011年全国大学生程序设计邀请赛(福州)

Submit  Back  Status  Discuss