#C2158. Direct and Group Messaging Simulator

    ID: 45443 Type: Default 1000ms 256MiB

Direct and Group Messaging Simulator

Direct and Group Messaging Simulator

You are given a simulation of a messaging system which supports two types of messages:

  • Direct messages — send a message to a specific user.
  • Group messages — send a message to every user in a given group.

The input consists of a list of users, a set of groups (each with its member users), and a sequence of commands. Each command is one of the two formats:

  • SEND <user> <message>: Send a direct message to user.
  • SEND_GROUP <group> <message>: Send a message to all users belonging to group.

Your task is to simulate the process of sending messages according to the commands and then output the final state of each user's message box in JSON format. All messages must appear in the order they were received.

Note: If a message is sent to a user or group that does not exist, ignore the command.

inputFormat

The input is read from stdin and is formatted as follows:

  1. An integer U representing the number of users.
  2. A line with U space-separated user names.
  3. An integer G representing the number of groups.
  4. G lines follow. Each line contains a group's details in the format: <group_name> <K> <user1> <user2> ... <userK>, where K is the number of users in that group.
  5. An integer C representing the number of commands.
  6. C lines follow, each representing a command in one of the following formats:
    • SEND <user> <message>
    • SEND_GROUP <group> <message>
    The <message> may contain spaces.

outputFormat

Output the final state of all users' message boxes in JSON format on stdout. The output JSON object should map each user name to an array of messages (strings) in the order in which they were received.

## sample
3
Alice Bob Charlie
3
Developers 2 Alice Bob
Designers 1 Charlie
Team 3 Alice Bob Charlie
3
SEND Alice Hello, Alice!
SEND_GROUP Team Hello, everyone!
SEND_GROUP Developers Code review at 5 PM
{"Alice": ["Hello, Alice!", "Hello, everyone!", "Code review at 5 PM"], "Bob": ["Hello, everyone!", "Code review at 5 PM"], "Charlie": ["Hello, everyone!"]}