#C11090. Process Microservices Messages in the SmallTritan Protocol

    ID: 40368 Type: Default 1000ms 256MiB

Process Microservices Messages in the SmallTritan Protocol

Process Microservices Messages in the SmallTritan Protocol

You are tasked with implementing a system that processes a sequence of commands representing messages exchanged between microservices using the SmallTritan protocol. Each command is provided in a single string where individual commands are separated by a semicolon (;). Each command consists of one or more components separated by the pipe character (|).

The set of valid commands is as follows:

  • USR|<username>: Register or log in a user identified by username.
  • SES|<session_id>: Activate or maintain a session with the given session_id.
  • SCB|<score>: Submit an integer score for the currently active user. If the submitted score is higher than a previously stored score for that user, update it.
  • LBD: Display the leaderboard, which lists each user and their highest score, sorted in descending order by score.

The expected behavior is illustrated in the following examples:

Example 1:

Input:  USR|john
Output: User john logged in

Example 2:

Input:  SES|123
Output: Session 123 activated

Example 3:

Input:  USR|john;SCB|50
Output:
User john logged in
Score 50 submitted

Example 4:

Input:  USR|john;SCB|50;USR|jane;SCB|60;LBD
Output:
User john logged in
Score 50 submitted
User jane logged in
Score 60 submitted
Leaderboard:
jane: 60
john: 50

Note: In our solution, the input will be provided via standard input (stdin) and the result should be printed to standard output (stdout). Ensure your implementation correctly handles multiple commands as well as command updates.

For any mathematical formulas that need to be included, please use LaTeX formatting. For example, the command format can be denoted as $\texttt{CMD|}$.

inputFormat

The input is a single line read from standard input (stdin) which contains one or more commands separated by semicolons (;).

outputFormat

The output should be printed to standard output (stdout). It is a series of responses corresponding to each command processed, each separated by a newline character.

## sample
USR|john
User john logged in