#K61447. Messaging System

    ID: 31311 Type: Default 1000ms 256MiB

Messaging System

Messaging System

You are required to implement a messaging system that supports two operations: sending messages and querying the message history between employees. The system stores each message as a record with a sender, a receiver, and the message text. When a query is made for two employees, you must retrieve and output all messages exchanged between them in the order they were sent, using the following format for each message:

from  sender  to  receiver:  messagefrom\;{sender}\;to\;{receiver}:\;{message}

Your program should read input from stdin and print the output to stdout.

inputFormat

The input begins with an integer Q representing the number of operations. Each operation is provided in one of the following formats:

  1. For sending a message:

    • A line containing the word send
    • A line containing the sender's name
    • A line containing the receiver's name
    • A line containing the message text
  2. For querying the message history:

    • A line containing the word query
    • A line containing the first employee's name
    • A line containing the second employee's name

All input is read from stdin.

outputFormat

For each query operation, output the total number of messages exchanged between the two specified employees on a single line. Then, output each message on a new line in the order they were sent. Each message should be formatted as:

from  sender  to  receiver:  messagefrom\;sender\;to\;receiver:\;message

All output should be written to stdout.## sample

7
send
Alice
Bob
Hello Bob!
send
Bob
Alice
Hi Alice!
send
Alice
Bob
How are you?
query
Alice
Bob
send
Carol
Dave
Hello Dave!
query
Carol
Dave
3

from Alice to Bob: Hello Bob! from Bob to Alice: Hi Alice! from Alice to Bob: How are you? 1 from Carol to Dave: Hello Dave!

</p>