#C9775. To-Do List Manager
To-Do List Manager
To-Do List Manager
You are required to implement a simple to-do list manager that processes a series of commands. The commands are given as input from stdin
and the outputs must be printed to stdout
.
The supported commands are:
- ADD <task>: Adds the text task to the end of the to-do list.
- REMOVE <index>: Removes the task at the given 1-based index if it exists.
- LIST: Prints all current tasks, each on a new line. If the list is empty, print
No tasks
.
In mathematical terms, let \(L\) be the list of tasks. An ADD operation appends an element \(x\) (i.e. \(L = L \cup \{x\}\)), and a REMOVE operation removes the \(i\)th element if \(1 \le i \le |L|\). A LIST command outputs the tasks if \(|L| > 0\), otherwise it outputs "No tasks".
inputFormat
The first line contains an integer n
representing the number of commands.
The next n
lines each contain a command. Commands can be one of the following forms:
ADD <task>
REMOVE <index>
LIST
Each command will be processed in the order they are provided.
outputFormat
For each LIST
command encountered in the input, output the current to-do list:
- If the to-do list is not empty, output each task on a new line in the order they were added.
- If the to-do list is empty, output
No tasks
.
The outputs should appear in the same order as the LIST
commands are processed.
3
ADD Buy groceries
ADD Call John
LIST
Buy groceries
Call John
</p>