#K61447. Messaging System
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:
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:
-
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
- A line containing the word
-
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
- A line containing the word
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:
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>