#K41957. To-Do List Manager
To-Do List Manager
To-Do List Manager
In this problem, you are required to implement a simple to-do list manager. The manager supports three commands:
- (\texttt{add }): Add a new task with a given name and integer priority. Each task is stored with the order in which it was added.
- (\texttt{complete }): Mark the specified task as completed.
- (\texttt{print}): Print all active (i.e., not completed) tasks. The tasks should be output in descending order of priority. If two tasks have the same priority, they should be printed in the order they were added.
All commands are processed in the order they are given. Your solution should read inputs from standard input (stdin) and output the result to standard output (stdout) whenever a (\texttt{print}) command is encountered.
inputFormat
The input consists of multiple lines. Each line represents a command in one of the following formats:
add <name> <priority>
— where<name>
is a string without spaces and<priority>
is an integer.complete <name>
— marks the task named<name>
as completed.print
— prints the active tasks as described in the output section.
outputFormat
Every time a print
command is encountered in the input, output all active (incomplete) tasks sorted by descending priority, and then by the order in which they were added (for tasks with the same priority). Each task name must be printed on a new line.## sample
add build_project 2
add write_report 3
add read_book 1
complete build_project
print
complete read_book
write_report
read_book
</p>