#C1416. Messaging System Simulation

    ID: 43778 Type: Default 1000ms 256MiB

Messaging System Simulation

Messaging System Simulation

You are required to implement a simple messaging system which supports three operations:

  • CREATE <username> — creates a new user with the given username. If the user already exists, do nothing.
  • SEND <sender> <recipient> <message> — sends a message from the sender to the recipient. The message text may contain spaces. If the recipient does not exist, the command is ignored.
  • VIEW <username> — displays all messages received by the specified user in the order they were received. Each message must be printed on its own line in the format sender: message. If the user does not exist or has not received any messages, print No messages.

The system reads commands from standard input. The first line contains a single integer \(N\) denoting the number of commands. The next \(N\) lines each contain one command. Only the VIEW command produces output which should be printed to standard output.

Example Usage:

Input:
6
CREATE Alice
VIEW Alice
CREATE Bob
SEND Alice Bob Hello, Bob!
VIEW Bob
VIEW Alice

Output: No messages Alice: Hello, Bob! No messages

</p>

inputFormat

The input begins with an integer \(N\) on the first line representing the number of commands. The following \(N\) lines each contain one command in one of the following formats:

  • CREATE <username>
  • SEND <sender> <recipient> <message> (the message may contain spaces)
  • VIEW <username>

outputFormat

For each VIEW <username> command, output the messages received by the user, each on its own line, in the order they were received. If the user does not exist or has no messages, output a single line with No messages.

## sample
6
CREATE Alice
VIEW Alice
CREATE Bob
SEND Alice Bob Hello, Bob!
VIEW Bob
VIEW Alice
No messages

Alice: Hello, Bob! No messages

</p>