SimeonTs

SUPyF2 P.-Mid-Exam/30 June 2019/2. - Tasks Planner

Oct 28th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 30 June 2019 Group 2
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1683#1
  4.  
  5. SUPyF2 P.-Mid-Exam/30 June 2019/2. - Tasks Planner
  6.  
  7. Problem:
  8. Create a program that helps you organize your daily tasks.
  9. First, you are going to receive the hours each task takes оn a single line, separated by space, in the following format:
  10. "{task1} {task2} {task3}… {taskn}"
  11. Each task takes from 1 to 5 hours. If its time is set to 0 – it is completed. If its time is set to a negative number –
  12. the task is dropped.
  13. Then you will start receiving commands until you read the "End" message. There are six possible commands:
  14. • "Complete {index}"
  15. o   Find the task on this index in your collection and complete it, if the index exists.
  16. • "Change {index} {time}"
  17. o   Replace the time needed of the task on the given index with the time given, if the index exists.
  18. • "Drop {index}"
  19. o   Drop the task on the given index, setting its hour to -1, if the index exists.
  20. • "Count Completed"
  21. o   Print the number of completed tasks.
  22. • "Count Incomplete"
  23. o   Print the number of incomplete tasks (this doesn’t include the dropped tasks).
  24. • "Count Dropped"
  25. o   Print the number of dropped tasks (this doesn’t include the incomplete tasks).
  26. In the end, print the incomplete tasks on a single line, separated by a single space in the following format:
  27. "{task1} {task2} {task3}… {taskn}"
  28. Input
  29. • On the 1st line you are going to receive the time of each task, separated by a single space.
  30. • On the next lines, until the "End" command is received, you will be receiving commands.
  31. Output:
  32. • Print the tasks in the format described above.
  33. Examples:
  34. Input:
  35. 1 -1 2 3 4 5
  36. Complete 4
  37. Change 0 4
  38. Drop 3
  39. Count Dropped
  40. End
  41.  
  42. Output:
  43. 2
  44. 4 2 5
  45.  
  46. Comments:
  47. First, we receive the command "Complete 4" and we to complete the task on index 4. After this command,
  48. the task collection looks like this:
  49. 1 -1 2 3 0 5
  50. Afterwards, we receive the "Change 0 4" command and we need to change the time of the task on index 0.
  51. The collection looks like this now:
  52. 4 -1 2 3 0 5
  53. After, we receive the "Drop 3" command, which means we need to drop the task on index 3. The collection looks like this:
  54. 4 -1 2 -1 0 5
  55. Then, we receive the "Count Dropped" command. The result is 2 as we have only 2 dropped tasks.
  56. In the end, we print all of the incomplete tasks. This is the result collection:
  57. 4 2 5
  58.  
  59. Input:
  60. 1 2 3 4 5 4 0 3 2 1
  61. Complete 0
  62. Complete 1
  63. Complete 2
  64. Drop 3
  65. Change 4 1
  66. Count Completed
  67. End
  68.  
  69. Output:
  70. 4
  71. 1 4 3 2 1
  72. """
  73. tasks = [int(task) for task in input().split()]
  74.  
  75. while True:
  76.     command = input().split()
  77.     if command[0] == "End":
  78.         break
  79.     elif command[0] == "Complete":
  80.         index = int(command[1])
  81.         if 0 <= index < len(tasks):
  82.             tasks[index] = 0
  83.  
  84.     elif command[0] == "Change":
  85.         index = int(command[1])
  86.         if 0 <= index < len(tasks):
  87.             tasks[index] = int(command[2])
  88.  
  89.     elif command[0] == "Drop":
  90.         index = int(command[1])
  91.         if 0 <= index < len(tasks):
  92.             tasks[index] = -1
  93.  
  94.     elif command[0] == "Count":
  95.         if command[1] == "Completed":
  96.             print(len([item for item in tasks if item == 0]))
  97.         elif command[1] == "Incomplete":
  98.             print(len([item for item in tasks if item > 0]))
  99.         elif command[1] == "Dropped":
  100.             print(len([item for item in tasks if item == -1]))
  101.  
  102. print(*[item for item in tasks if item > 0])
Add Comment
Please, Sign In to add comment