#C13586. Task Manager Command Processor

    ID: 43140 Type: Default 1000ms 256MiB

Task Manager Command Processor

Task Manager Command Processor

You are required to implement a task management system that processes a series of commands from standard input. The system supports operations to add a task, list all tasks, mark a task as completed, and delete a task. Each task has a description, a due date in the format (YYYY-MM-DD), and a completion status. Your program should read commands from standard input and write responses to standard output. The commands are given in the following format:

  • ADD <description> <due_date>: Adds a new task. If the due date does not match the required format \(YYYY-MM-DD\), output the error message Invalid date format, should be YYYY-MM-DD and do not add the task.
  • LIST: Lists all tasks. For each task, output a line in the format: description | due_date | completed, where completed is either True or False.
  • COMPLETE <index>: Marks the task at the given zero-based index as completed. If the index is invalid, output Invalid task index.
  • DELETE <index>: Deletes the task at the given index. If the index is invalid, output Invalid task index.

Note: The description is a single word (without spaces) and the due date must strictly follow the format \(YYYY-MM-DD\).

inputFormat

The first line of input contains an integer (T) representing the number of commands. The following (T) lines each contain a command. Valid commands are:

  • ADD <description> <due_date>
  • LIST
  • COMPLETE <index>
  • DELETE <index>

For example:
5 ADD Task1 2023-12-01 ADD Task2 2023-12-02 LIST COMPLETE 0 LIST

outputFormat

For each command, the program outputs a response to standard output:

  • ADD: Outputs Task added successfully if the task is added or Invalid date format, should be YYYY-MM-DD if the due date is invalid.
  • LIST: Outputs each task on a separate line in the format description | due_date | completed.
  • COMPLETE: Outputs Task marked as completed if the operation succeeds; otherwise, outputs Invalid task index.
  • DELETE: Outputs Task deleted successfully if the deletion is successful; otherwise, outputs Invalid task index.

All outputs should be printed to standard output.## sample
5
ADD Task1 2023-12-01
ADD Task2 2023-12-02
LIST
COMPLETE 0
LIST
Task added successfully

Task added successfully Task1 | 2023-12-01 | False Task2 | 2023-12-02 | False Task marked as completed Task1 | 2023-12-01 | True Task2 | 2023-12-02 | False

</p>