#K64707. Logger Implementation
Logger Implementation
Logger Implementation
Implement a Logger class that manages log messages by providing three operations:
ADD <message>
: Adds a new log message.GET
: Retrieves and outputs the latest log message. If no logs exist, it outputsNo logs
.CLEAR
: Clears all stored log messages.
The program reads commands from standard input and outputs the results of GET
commands to standard output. The input starts with an integer specifying the number of commands, followed by each command on a new line. The ADD
command is followed by a space and the message text, while GET
and CLEAR
appear alone.
For example, given the following commands:
5 GET ADD Starting the server. GET ADD New log message. GET
The expected output is:
No logs Starting the server. New log message.
inputFormat
The input begins with an integer N
denoting the number of operations. Each of the following N
lines contains one of the following commands:
- ADD <message>: Add a new log message. The message may contain spaces.
- GET: Print the current latest log message.
- CLEAR: Remove all stored log messages.
outputFormat
For each GET
command in the input, output one line containing the logger's latest message. If there are no log messages present, output No logs
.
5
GET
ADD Starting the server.
GET
ADD New log message.
GET
No logs
Starting the server.
New log message.
</p>